From f6763e95845d9c4d99de73c7924f44e3bc6e261c Mon Sep 17 00:00:00 2001 From: Brice Theurillat Date: Fri, 14 Oct 2016 17:21:36 +0200 Subject: [PATCH 01/12] Adding definitions for the "plugapi" package --- plugapi/plugapi-tests.ts | 17 ++ plugapi/plugapi.d.ts | 420 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 437 insertions(+) create mode 100644 plugapi/plugapi-tests.ts create mode 100644 plugapi/plugapi.d.ts diff --git a/plugapi/plugapi-tests.ts b/plugapi/plugapi-tests.ts new file mode 100644 index 0000000000..352b002094 --- /dev/null +++ b/plugapi/plugapi-tests.ts @@ -0,0 +1,17 @@ +/// + +import * as PlugAPI from "plugapi"; + +let yolo = new PlugAPI({ + email: "", + password: "" +}, function (err,bot) { + if (!err) { + bot.connect("roomslug"); // The part after https://plug.dj + bot.on("roomJoin", function (room) { + console.log("Joined " + room); + }); + } else { + console.log("Error initializing plugAPI: " + err); + } +}); \ No newline at end of file diff --git a/plugapi/plugapi.d.ts b/plugapi/plugapi.d.ts new file mode 100644 index 0000000000..ecbf5f9379 --- /dev/null +++ b/plugapi/plugapi.d.ts @@ -0,0 +1,420 @@ +// Type definitions for plugapi +// Project: https://www.npmjs.com/package/plugapi +// Definitions by: Brice Theurillat +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "plugapi" { + interface PlugLogin { + email: string; + password: string; + } + + interface Notification { + action: string; + id: number; + timestamp: string; + value: string; + } + + interface RawChatMessage { + cid: string; + message: string; + sub: number; + uid: number; + un: string; + } + + interface Media { + author: string; + format: 1; + image: string; + cid: string; + duration: number; + title: string; + id: number; + } + + interface Score { + positive: number; + listeners: number; + grabs: number; + negative: number; + skipped: number; + } + + interface LastPlay { + dj: User.DJ; + media: Media; + score: Score; + } + + interface FollowJoinData { + r: number; + un: string; + id: string; + } + + interface LogObject { + log: () => void; + } + + namespace User { + interface Default { + username: string; + language: string; + avatarID: string; + } + + interface Extended extends Default { + status: number; + fans: number; + listenerPoints: number; + id: string; + curatorPoints: number; + djPoints: number; + } + + interface Update extends Extended { + dateJoined: string; + } + + interface Room extends Default { + sub: number; + level: number; + joined: string; + id: number; + badge: string; + role: number; + gRole: number; + slug: string; + } + + interface User extends Room { + silver: boolean; + guest: boolean; + } + + interface DJ extends Room { + blurp: any; + grab: boolean; + status: number; + vote: number; + } + + interface Audience extends DJ { + ignores: any[]; + notifications: Notification[]; + pp: number; + pw: number; + xp: number; + } + } + + namespace Enum { + interface RoomRole { + NONE: 0, + RESIDENTDJ: 1, + BOUNCER: 2, + MANAGER: 3, + COHOST: 4, + HOST: 5 + } + + interface GlobalRole { + NONE: 0, + VOLUNTEER: 2, + AMBASSADOR: 3, + LEADER: 4, + ADMIN: 5 + } + + interface Status { + OFFLINE: 0, + ONLINE: 1 + } + + interface Ban { + HOUR: "h", + DAY: "d", + PERMA: "f" + } + + interface BanReason { + SPAMMING_TROLLING: 1, + VERBAL_ABUSE: 2, + OFFENSIVE_MEDIA: 3, + INAPPROPRIATE_GENRE: 4, + NEGATIVE_ATTITUDE: 5 + } + + interface Mute { + SHORT: "s", + MEDIUM: "m", + LONG: "l" + } + + interface MuteReason { + VIOLATING_COMMUNITY_RULES: 1, + VERBAL_ABUSE: 2, + SPAMMING_TROLLING: 3, + OFFENSIVE_LANGUAGE: 4, + NEGATIVE_ATTITUDE: 5 + } + + interface Events { + ADVANCE: "advance", + BAN: "ban", + BOOTH_LOCKED: "boothLocked", + CHAT: "chat", + CHAT_COMMAND: "command", + CHAT_DELETE: "chatDelete", + CHAT_LEVEL_UPDATE: "roomMinChatLevelUpdate", + COMMAND: "command", + DJ_LIST_CYCLE: "djListCycle", + DJ_LIST_UPDATE: "djListUpdate", + DJ_LIST_LOCKED: "djListLocked", + EARN: "earn", + FOLLOW_JOIN: "followJoin", + FLOOD_CHAT: "floodChat", + FRIEND_REQUEST: "friendRequest", + GIFTED: "gifted", + GRAB: "grab", + KILL_SESSION: "killSession", + MAINT_MODE: "plugMaintenance", + MAINT_MODE_ALERT: "plugMaintenanceAlert", + MODERATE_ADD_DJ: "modAddDJ", + MODERATE_ADD_WAITLIST: "modAddWaitList", + MODERATE_AMBASSADOR: "modAmbassador", + MODERATE_BAN: "modBan", + MODERATE_MOVE_DJ: "modMoveDJ", + MODERATE_MUTE: "modMute", + MODERATE_REMOVE_DJ: "modRemoveDJ", + MODERATE_REMOVE_WAITLIST: "modRemoveWaitList", + MODERATE_SKIP: "modSkip", + MODERATE_STAFF: "modStaff", + NOTIFY: "notify", + PDJ_MESSAGE: "pdjMessage", + PDJ_UPDATE: "pdjUpdate", + PING: "ping", + PLAYLIST_CYCLE: "playlistCycle", + REQUEST_DURATION: "requestDuration", + REQUEST_DURATION_RETRY: "requestDurationRetry", + ROOM_CHANGE: "roomChanged", + ROOM_DESCRIPTION_UPDATE: "roomDescriptionUpdate", + ROOM_JOIN: "roomJoin", + ROOM_NAME_UPDATE: "roomNameUpdate", + ROOM_VOTE_SKIP: "roomVoteSkip", + ROOM_WELCOME_UPDATE: "roomWelcomeUpdate", + SESSION_CLOSE: "sessionClose", + SKIP: "skip", + STROBE_TOGGLE: "strobeToggle", + USER_COUNTER_UPDATE: "userCounterUpdate", + USER_FOLLOW: "userFollow", + USER_JOIN: "userJoin", + USER_LEAVE: "userLeave", + USER_UPDATE: "userUpdate", + VOTE: "vote" + } + } + + namespace Event { + interface BoothCycle { + moderator: string; + cycle: true; + } + + interface BoothLocked { + m: string; + c: boolean; + ml: string; + f: boolean; + } + + interface Chat { + raw: RawChatMessage; + id: string; + from: User.User; + message: string; + mentions: Array; + muted: boolean; + type: string; + } + + interface ChatDelete { + mi: number; + chatID: string; + } + + type Grab = number; + + interface Advance { + media: Media; + startTime: string; + historyID: string; + djs: User.DJ[]; + currentDJ: User.DJ; + playlistID: number; + lastPlay: LastPlay; + } + + interface DJListUpdate { + djs: User.DJ[]; + remove: string; + } + + interface Emote { + fromID: string; + message: string; + from: string; + type: string; + chatID: string; + } + + interface FollowJoin { + data: FollowJoinData; + type: string; + } + + interface ModAddDJ { + moderator: string; + username: string; + } + + interface ModBan { + moderator: string; + username: string; + duration: number; + ref: string; + reason: string; + } + + interface ModMoveDJ { + moderator: string; + index: number; + old: number; + userID: string; + } + + interface ModRemoveDJ { + moderator: string; + username: string; + userID: string; + } + + interface ModSkip { + mi: number; + m: string; + } + + interface RoomMinChatLevelUpdate { + level: number; + id: number; + user: User.User; + } + + type RoomJoin = string; + + type UserJoin = User.User; + + type UserLeave = User.User; + + interface UserUpdate { + username: string; + status: number; + fans: number; + listenerPoints: number; + dateJoined: string; + language: string; + avatarID: string; + id: string; + curatorPoints: number; + djPoints: number; + } + + interface Vote { + i: number; + v: number; + } + + interface Command extends Event.Chat { + command: string; + args: string[]; + respond: Function; + respondTimeout: Function; + havePermission: Function; + isFrom: Function; + } + } + + interface PlugAPIInstance { + deleteAllChat: boolean; + multiLine: boolean; + multiLineLimit: number; + + connect(room: string): void; + changeDJCycle(enabled: boolean, callback?: () => void): boolean; + changeRoom(room: string, callback?: () => void): void; + close(): void; + getAdmins(): User.Extended[]; + getAmbassadors(): User.Extended[]; + getAudience(): User.Audience[]; + getDJ(): User.DJ; + getDJs(): User.DJ[]; + getHost(): User.Extended; + getMedia(): Media; + getRoomScore(): Score; + getSelf(): User.Audience; + getStaff(): User.Extended[]; + getTimeElapsed(): number; + getTimeRemaining(): number; + getUser(userID: number): User.DJ; + getUsers(): User.DJ[]; + getWaitList(): User.Extended; + getWaitListPosition(userID: number): number; + havePermission(userID: number, permission: number, global?: boolean): boolean; + joinBooth(callback?: () => void): boolean; + leaveBooth(callback?: () => void): boolean; + selfSkip(callback?: () => void): boolean; + sendChat(msg: string, timeout?: number): void; + setLogger(logObject: LogObject): boolean; + + on(event: "boothCycle", callback: (data: Event.BoothCycle) => void): void; + on(event: "boothLocked", callback: (data: Event.BoothLocked) => void): void; + on(event: "chat", callback: (data: Event.Chat) => void): void; + on(event: "chatDelete", callback: (data: Event.ChatDelete) => void): void; + on(event: "grab", callback: (data: Event.Grab) => void): void; + on(event: "advance", callback: (data: Event.Advance) => void): void; + on(event: "djListUpdate", callback: (data: Event.DJListUpdate) => void): void; + on(event: "emote", callback: (data: Event.Emote) => void): void; + on(event: "followJoin", callback: (data: Event.FollowJoin) => void): void; + on(event: "modAddDJ", callback: (data: Event.ModAddDJ) => void): void; + on(event: "modBan", callback: (data: Event.ModBan) => void): void; + on(event: "modMoveDJ", callback: (data: Event.ModMoveDJ) => void): void; + on(event: "modRemoveDJ", callback: (data: Event.ModRemoveDJ) => void): void; + on(event: "modSkip", callback: (data: Event.ModSkip) => void): void; + on(event: "roomMinChatLevelUpdate", callback: (data: Event.RoomMinChatLevelUpdate) => void): void; + on(event: "roomJoin", callback: (data: Event.RoomJoin) => void): void; + on(event: "userJoin", callback: (data: Event.UserJoin) => void): void; + on(event: "userLeave", callback: (data: Event.UserLeave) => void): void; + on(event: "userUpdate", callback: (data: Event.UserUpdate) => void): void; + on(event: "vote", callback: (data: Event.Vote) => void): void; + on(event: "command", callback: (data: Event.Command) => void): void; + on(event: string, callback: (data: any) => void): void; + } + + interface PlugAPIStatic { + new (login: PlugLogin, callback?: (error: Error, bot: PlugAPIInstance) => void): PlugAPIInstance; + new (login: PlugLogin, callback?: (bot: PlugAPIInstance) => void): PlugAPIInstance; + ROOM_ROLE: Enum.RoomRole; + GLOBAL_ROLES: Enum.GlobalRole; + STATUS: Enum.Status; + BAN: Enum.Ban; + BAN_REASON: Enum.BanReason; + MUTE: Enum.Mute; + MUTE_REASON: Enum.MuteReason; + events: Enum.Events; + } + + var PlugAPI: PlugAPIStatic; + export = PlugAPI; +} \ No newline at end of file From 78ec017787b192652ada4cccf2b626e4f1407e5a Mon Sep 17 00:00:00 2001 From: Brice Theurillat Date: Fri, 14 Oct 2016 17:31:53 +0200 Subject: [PATCH 02/12] Correct typings errors --- plugapi/plugapi.d.ts | 166 +++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/plugapi/plugapi.d.ts b/plugapi/plugapi.d.ts index ecbf5f9379..90351ac53a 100644 --- a/plugapi/plugapi.d.ts +++ b/plugapi/plugapi.d.ts @@ -26,7 +26,7 @@ declare module "plugapi" { interface Media { author: string; - format: 1; + format: number; image: string; cid: string; duration: number; @@ -112,115 +112,115 @@ declare module "plugapi" { namespace Enum { interface RoomRole { - NONE: 0, - RESIDENTDJ: 1, - BOUNCER: 2, - MANAGER: 3, - COHOST: 4, - HOST: 5 + NONE: number; + RESIDENTDJ: number; + BOUNCER: number; + MANAGER: number; + COHOST: number; + HOST: number; } interface GlobalRole { - NONE: 0, - VOLUNTEER: 2, - AMBASSADOR: 3, - LEADER: 4, - ADMIN: 5 + NONE: number; + VOLUNTEER: number; + AMBASSADOR: number; + LEADER: number; + ADMIN: number; } interface Status { - OFFLINE: 0, - ONLINE: 1 + OFFLINE: number; + ONLINE: number; } interface Ban { - HOUR: "h", - DAY: "d", - PERMA: "f" + HOUR: "h"; + DAY: "d"; + PERMA: "f"; } interface BanReason { - SPAMMING_TROLLING: 1, - VERBAL_ABUSE: 2, - OFFENSIVE_MEDIA: 3, - INAPPROPRIATE_GENRE: 4, - NEGATIVE_ATTITUDE: 5 + SPAMMING_TROLLING: number; + VERBAL_ABUSE: number; + OFFENSIVE_MEDIA: number; + INAPPROPRIATE_GENRE: number; + NEGATIVE_ATTITUDE: number; } interface Mute { - SHORT: "s", - MEDIUM: "m", - LONG: "l" + SHORT: "s"; + MEDIUM: "m"; + LONG: "l"; } interface MuteReason { - VIOLATING_COMMUNITY_RULES: 1, - VERBAL_ABUSE: 2, - SPAMMING_TROLLING: 3, - OFFENSIVE_LANGUAGE: 4, - NEGATIVE_ATTITUDE: 5 + VIOLATING_COMMUNITY_RULES: number; + VERBAL_ABUSE: number; + SPAMMING_TROLLING: number; + OFFENSIVE_LANGUAGE: number; + NEGATIVE_ATTITUDE: number; } interface Events { - ADVANCE: "advance", - BAN: "ban", - BOOTH_LOCKED: "boothLocked", - CHAT: "chat", - CHAT_COMMAND: "command", - CHAT_DELETE: "chatDelete", - CHAT_LEVEL_UPDATE: "roomMinChatLevelUpdate", - COMMAND: "command", - DJ_LIST_CYCLE: "djListCycle", - DJ_LIST_UPDATE: "djListUpdate", - DJ_LIST_LOCKED: "djListLocked", - EARN: "earn", - FOLLOW_JOIN: "followJoin", - FLOOD_CHAT: "floodChat", - FRIEND_REQUEST: "friendRequest", - GIFTED: "gifted", - GRAB: "grab", - KILL_SESSION: "killSession", - MAINT_MODE: "plugMaintenance", - MAINT_MODE_ALERT: "plugMaintenanceAlert", - MODERATE_ADD_DJ: "modAddDJ", - MODERATE_ADD_WAITLIST: "modAddWaitList", - MODERATE_AMBASSADOR: "modAmbassador", - MODERATE_BAN: "modBan", - MODERATE_MOVE_DJ: "modMoveDJ", - MODERATE_MUTE: "modMute", - MODERATE_REMOVE_DJ: "modRemoveDJ", - MODERATE_REMOVE_WAITLIST: "modRemoveWaitList", - MODERATE_SKIP: "modSkip", - MODERATE_STAFF: "modStaff", - NOTIFY: "notify", - PDJ_MESSAGE: "pdjMessage", - PDJ_UPDATE: "pdjUpdate", - PING: "ping", - PLAYLIST_CYCLE: "playlistCycle", - REQUEST_DURATION: "requestDuration", - REQUEST_DURATION_RETRY: "requestDurationRetry", - ROOM_CHANGE: "roomChanged", - ROOM_DESCRIPTION_UPDATE: "roomDescriptionUpdate", - ROOM_JOIN: "roomJoin", - ROOM_NAME_UPDATE: "roomNameUpdate", - ROOM_VOTE_SKIP: "roomVoteSkip", - ROOM_WELCOME_UPDATE: "roomWelcomeUpdate", - SESSION_CLOSE: "sessionClose", - SKIP: "skip", - STROBE_TOGGLE: "strobeToggle", - USER_COUNTER_UPDATE: "userCounterUpdate", - USER_FOLLOW: "userFollow", - USER_JOIN: "userJoin", - USER_LEAVE: "userLeave", - USER_UPDATE: "userUpdate", - VOTE: "vote" + ADVANCE: "advance"; + BAN: "ban"; + BOOTH_LOCKED: "boothLocked"; + CHAT: "chat"; + CHAT_COMMAND: "command"; + CHAT_DELETE: "chatDelete"; + CHAT_LEVEL_UPDATE: "roomMinChatLevelUpdate"; + COMMAND: "command"; + DJ_LIST_CYCLE: "djListCycle"; + DJ_LIST_UPDATE: "djListUpdate"; + DJ_LIST_LOCKED: "djListLocked"; + EARN: "earn"; + FOLLOW_JOIN: "followJoin"; + FLOOD_CHAT: "floodChat"; + FRIEND_REQUEST: "friendRequest"; + GIFTED: "gifted"; + GRAB: "grab"; + KILL_SESSION: "killSession"; + MAINT_MODE: "plugMaintenance"; + MAINT_MODE_ALERT: "plugMaintenanceAlert"; + MODERATE_ADD_DJ: "modAddDJ"; + MODERATE_ADD_WAITLIST: "modAddWaitList"; + MODERATE_AMBASSADOR: "modAmbassador"; + MODERATE_BAN: "modBan"; + MODERATE_MOVE_DJ: "modMoveDJ"; + MODERATE_MUTE: "modMute"; + MODERATE_REMOVE_DJ: "modRemoveDJ"; + MODERATE_REMOVE_WAITLIST: "modRemoveWaitList"; + MODERATE_SKIP: "modSkip"; + MODERATE_STAFF: "modStaff"; + NOTIFY: "notify"; + PDJ_MESSAGE: "pdjMessage"; + PDJ_UPDATE: "pdjUpdate"; + PING: "ping"; + PLAYLIST_CYCLE: "playlistCycle"; + REQUEST_DURATION: "requestDuration"; + REQUEST_DURATION_RETRY: "requestDurationRetry"; + ROOM_CHANGE: "roomChanged"; + ROOM_DESCRIPTION_UPDATE: "roomDescriptionUpdate"; + ROOM_JOIN: "roomJoin"; + ROOM_NAME_UPDATE: "roomNameUpdate"; + ROOM_VOTE_SKIP: "roomVoteSkip"; + ROOM_WELCOME_UPDATE: "roomWelcomeUpdate"; + SESSION_CLOSE: "sessionClose"; + SKIP: "skip"; + STROBE_TOGGLE: "strobeToggle"; + USER_COUNTER_UPDATE: "userCounterUpdate"; + USER_FOLLOW: "userFollow"; + USER_JOIN: "userJoin"; + USER_LEAVE: "userLeave"; + USER_UPDATE: "userUpdate"; + VOTE: "vote"; } } namespace Event { interface BoothCycle { moderator: string; - cycle: true; + cycle: boolean; } interface BoothLocked { From 8f4f35541f60fea1234bea231a213b678b064207 Mon Sep 17 00:00:00 2001 From: Brice Theurillat Date: Fri, 14 Oct 2016 20:45:50 +0200 Subject: [PATCH 03/12] Modify test file --- plugapi/plugapi-tests.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/plugapi/plugapi-tests.ts b/plugapi/plugapi-tests.ts index 352b002094..279a5b659d 100644 --- a/plugapi/plugapi-tests.ts +++ b/plugapi/plugapi-tests.ts @@ -2,15 +2,33 @@ import * as PlugAPI from "plugapi"; -let yolo = new PlugAPI({ +new PlugAPI({ email: "", password: "" -}, function (err,bot) { +}, function (err, bot) { if (!err) { - bot.connect("roomslug"); // The part after https://plug.dj - bot.on("roomJoin", function (room) { + const ROOM = "roomslug"; + bot.connect(ROOM); // The part after https://plug.dj + + bot.on(PlugAPI.events.ROOM_JOIN, function (room) { console.log("Joined " + room); }); + + bot.on("chat", function (data) { + if (data.type == "emote") { + console.log(data.from + data.message); + } else { + console.log(data.from + "> " + data.message); + } + }); + + bot.on("error", function () { + bot.connect(ROOM); + }); + + bot.deleteAllChat = false; + bot.multiLine = true; + bot.multiLineLimit = 5; } else { console.log("Error initializing plugAPI: " + err); } From 303dd0fb1b76a7dd00c452b68484cc34f177348e Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Sun, 16 Oct 2016 20:13:00 +0200 Subject: [PATCH 04/12] add type definitions for 'random-seed' package --- random-seed/random-seed-tests.ts | 20 +++++++++++++++++++ random-seed/random-seed.d.ts | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 random-seed/random-seed-tests.ts create mode 100644 random-seed/random-seed.d.ts diff --git a/random-seed/random-seed-tests.ts b/random-seed/random-seed-tests.ts new file mode 100644 index 0000000000..9cbfda6766 --- /dev/null +++ b/random-seed/random-seed-tests.ts @@ -0,0 +1,20 @@ +/// +import * as gen from "random-seed"; + +// these generators produce different numbers +let rand1 = gen.create(); // method 1 +let rand2 = gen(); // method 3 + +// these generators will produce +// the same sequence of numbers +let seed = 'My Secret String Value'; +let rand3 = gen.create(seed); +let rand4 = gen(seed); + +// API +rand1.addEntropy(); +rand1.random(); +rand1.range(100); +rand1.intBetween(0, 10); +rand1.floatBetween(0, 1); +rand1.seed("new seed"); diff --git a/random-seed/random-seed.d.ts b/random-seed/random-seed.d.ts new file mode 100644 index 0000000000..e459a89cf8 --- /dev/null +++ b/random-seed/random-seed.d.ts @@ -0,0 +1,33 @@ +// Type definitions for random-seed 0.3.0 +// Project: https://github.com/skratchdot/random-seed/ +// Definitions by: Endel Dreyer +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "random-seed" { + + interface RandomSeed { + range (range: number): number; + random (): number; + floatBetween (min: number, max: number): number; + intBetween (min: number, max: number): number; + + string (count: number): string; + seed (seed: string): void; + + cleanString (inStr: string): string; + hashString (inStr: string): string; + + addEntropy (...args: any[]): void; + initState (): void; + + done (): void; + } + + function create (seed?: string): RandomSeed; + + namespace create { + function create(seed?: string): RandomSeed; + } + + export = create; +} From bb55a1f2d04d7a4d976d9154818d54c4e5b6e711 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Sun, 16 Oct 2016 21:16:06 +0200 Subject: [PATCH 05/12] export interface and create method instead of default export --- random-seed/random-seed-tests.ts | 8 +++----- random-seed/random-seed.d.ts | 9 ++------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/random-seed/random-seed-tests.ts b/random-seed/random-seed-tests.ts index 9cbfda6766..de49c65e45 100644 --- a/random-seed/random-seed-tests.ts +++ b/random-seed/random-seed-tests.ts @@ -1,15 +1,13 @@ /// -import * as gen from "random-seed"; +import { RandomSeed, create } from "random-seed"; // these generators produce different numbers -let rand1 = gen.create(); // method 1 -let rand2 = gen(); // method 3 +let rand1: RandomSeed = create(); // method 1 // these generators will produce // the same sequence of numbers let seed = 'My Secret String Value'; -let rand3 = gen.create(seed); -let rand4 = gen(seed); +let rand2 = create(seed); // API rand1.addEntropy(); diff --git a/random-seed/random-seed.d.ts b/random-seed/random-seed.d.ts index e459a89cf8..2dcb02d1e6 100644 --- a/random-seed/random-seed.d.ts +++ b/random-seed/random-seed.d.ts @@ -5,7 +5,7 @@ declare module "random-seed" { - interface RandomSeed { + export interface RandomSeed { range (range: number): number; random (): number; floatBetween (min: number, max: number): number; @@ -23,11 +23,6 @@ declare module "random-seed" { done (): void; } - function create (seed?: string): RandomSeed; + export function create (seed?: string): RandomSeed; - namespace create { - function create(seed?: string): RandomSeed; - } - - export = create; } From b39197548bb38c7a724b2bb50a8821220553dbc4 Mon Sep 17 00:00:00 2001 From: phijaen Date: Tue, 25 Oct 2016 13:41:03 +0200 Subject: [PATCH 06/12] Update the kendo throttle function definition The return type of the kendo throttle function should be Function instead of void (see usage at : http://docs.telerik.com/kendo-ui/api/javascript/kendo#methods-throttle ) --- kendo-ui/kendo-ui.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kendo-ui/kendo-ui.d.ts b/kendo-ui/kendo-ui.d.ts index ac6022ecd4..5ae6f7fe43 100644 --- a/kendo-ui/kendo-ui.d.ts +++ b/kendo-ui/kendo-ui.d.ts @@ -16947,7 +16947,7 @@ declare namespace kendo { function resize(element: Element, force: boolean): void; function saveAs(options: any): void; function stringify(value: any): string; - function throttle(fn: Function, timeout: number): void; + function throttle(fn: Function, timeout: number): Function; function touchScroller(element: string): void; function touchScroller(element: JQuery): void; function touchScroller(element: Element): void; From d54b6ce42048c50b083fb7c89d11bdc7a42dcff3 Mon Sep 17 00:00:00 2001 From: Diogo do Carmo Date: Tue, 25 Oct 2016 15:36:46 -0200 Subject: [PATCH 07/12] Updated NavigationCardStack to not extend from NavigationRoute According to this: https://github.com/facebook/react-native/blob/9ee815f6b52e0c2417c04e5a05e1e31df26daed2/Libraries/NavigationExperimental/NavigationPropTypes.js --- react-native/react-native.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index 4cc5d47449..713da055ec 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -7490,7 +7490,7 @@ declare namespace __React { key: string; } - export interface NavigationState extends NavigationRoute { + export interface NavigationState { index: number; routes: NavigationRoute[]; } From d1d3362998b75a764f53df32097541166b71c490 Mon Sep 17 00:00:00 2001 From: ofirgeller Date: Tue, 25 Oct 2016 14:23:32 -0400 Subject: [PATCH 08/12] switch and switchLatest are like a flatMap a stream of streams of T is mapped to a stream of T. --- rx/rx-lite.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rx/rx-lite.d.ts b/rx/rx-lite.d.ts index f159979204..ecaf1145d6 100644 --- a/rx/rx-lite.d.ts +++ b/rx/rx-lite.d.ts @@ -261,8 +261,8 @@ declare namespace Rx { mergeObservable(): Observable; // alias for mergeAll skipUntil(other: Observable): Observable; skipUntil(other: IPromise): Observable; - switch(): Observable; - switchLatest(): Observable; // alias for switch + switch(): T; + switchLatest(): T; // alias for switch takeUntil(other: Observable): Observable; takeUntil(other: IPromise): Observable; zip(second: Observable|IPromise): Observable<[T, T2]>; From ad257a2eaa9f4c4a9ee151ca4d4d2ab31dc842c1 Mon Sep 17 00:00:00 2001 From: laszlojakab Date: Tue, 25 Oct 2016 21:12:05 +0200 Subject: [PATCH 09/12] Create math3d.d.ts --- math3d/math3d.d.ts | 170 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 math3d/math3d.d.ts diff --git a/math3d/math3d.d.ts b/math3d/math3d.d.ts new file mode 100644 index 0000000000..4d89db48ac --- /dev/null +++ b/math3d/math3d.d.ts @@ -0,0 +1,170 @@ +// Type definitions for math3.d.ts +// Project: https://github.com/adragonite/math3d +// Definitions by: Laszlo Jakab +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "math3d" { + export class Vector3 { + constructor(x?: number, y?: number, z?: number); + + public static back: Vector3; + public static down: Vector3; + public static forward: Vector3; + public static left: Vector3; + public static one: Vector3; + public static right: Vector3; + public static up: Vector3; + public static zero: Vector3; + public static dimension: number; + public static FromVector4: (vector4: Vector4) => Vector3; + + public homogeneous: Vector4; + public magnitude: number; + public values: number[]; + public vector4: Vector4; + public x: number; + public y: number; + public z: number; + + public add(vector3: Vector3): Vector3; + public average(vector3: Vector3): Vector3; + public cross(vector3: Vector3): Vector3; + public distanceTo(vector3: Vector3): number; + public dot(vector3: Vector3): number; + public equals(vector3: Vector3): boolean; + public mulScalar(scalar: Number): Vector3; + public negate(): Vector3; + public normalize(): Vector3; + public scale(vector3: Vector3): Vector3; + public sub(vector3: Vector3): Vector3; + public toString(): string; + } + + export class Vector4 { + constructor(x?: number, y?: number, z?: number, w?: number); + + public static one: Vector4; + public static zero: Vector4; + public static dimension: number; + + public magnitude: number; + public values: number[]; + public x: number; + public y: number; + public z: number; + public w: number; + + public add(vector4: Vector4): Vector4; + public distanceTo(vector4: Vector4): number; + public dot(vector4: Vector4): number; + public equals(vector4: Vector4): boolean; + public mulScalar(scalar: Number): Vector4; + public negate(): Vector4; + public normalize(): Vector3; + public sub(vector4: Vector4): Vector3; + public toString(): string; + } + + export class Quaternion { + constructor(x?: number, y?: number, z?: number, w?: number); + public static Euler(x?: number, y?: number, z?: number): Quaternion; + public static AngleAxis(axis: Vector3, angle: number): Quaternion; + + public static identity: Quaternion; + public static zero: Quaternion; + + public angleAxis: { axis: Vector3, angle: number }; + public eulerAngles: { x: number, y: number, z: number }; + public x: number; + public y: number; + public z: number; + public w: number; + + public angleTo(quaternion: Quaternion): number; + public conjugate(): Quaternion; + public distanceTo(quaternion: Quaternion): number; + public dot(quaternion: Quaternion): number; + public equals(quaternion: Quaternion): boolean; + public inverse(): Quaternion; + public mul(quaternion: Quaternion): Quaternion; + public mulVector3(vector3: Vector3): Vector3; + public toString(): string; + } + + export class Matrix4x4 { + constructor(data: number[]); + + public static FlipMatrix(flipX: boolean, flipY: boolean, flipZ: boolean): Matrix4x4; + public static ScaleMatrix(scale: number | Vector3): Matrix4x4; + public static RotationMatrix(quaternion: Quaternion): Matrix4x4; + public static TranslationMatrix(translation: Vector3): Matrix4x4; + public static TRS(translation: Vector3, rotation: Quaternion, scale: number | Vector3): Matrix4x4; + public static LocalToWorldMatrix(position: Vector3, rotation: Quaternion, scale: number | Vector3): Matrix4x4; + public static WorldToLocalMatrix(position: Vector3, rotation: Quaternion, scale: number | Vector3): Matrix4x4; + + public static identity: Matrix4x4; + public static zero: Matrix4x4; + + public columns: number[][]; + public m11: number; + public m12: number; + public m13: number; + public m14: number; + public m21: number; + public m22: number; + public m23: number; + public m24: number; + public m31: number; + public m32: number; + public m33: number; + public m34: number; + public m41: number; + public m42: number; + public m43: number; + public m44: number; + public rows: number[][]; + public size: { rows: number, columns: number }; + public values: number[]; + + public determinant(): number + public inverse(): Matrix4x4; + public negate(): Matrix4x4; + public transpose(): Matrix4x4; + public add(matrix4x4: Matrix4x4): Matrix4x4; + public sub(matrix4x4: Matrix4x4): Matrix4x4; + public mul(matrix4x4: Matrix4x4): Matrix4x4; + public mulScalar(scalar: Number): Matrix4x4; + public mulVector3(vector3: Vector3): Vector3; + } + + export class Transform { + constructor(position?: Vector3, rotation?: Quaternion); + + public forward: Vector3; + public localPosition: Vector3; + public localRotation: Quaternion; + public localToWorldMatrix: Matrix4x4; + public name: string; + public parent: Transform; + public position: Vector3; + public right: Vector3; + public root: Transform; + public rotation: Vector3; + public up: Vector3; + public worldToLocalMatrix: Matrix4x4; + + public addChild(child: Transform): void; + public inverseTransformPosition(position: Vector3): Vector3; + public removeChild(child: Transform): void; + public transformPosition(position: Vector3): Vector3; + public translate(translation: Vector3, relativeTo?: Transform.Space): Transform; + public rotate(x: number, y: number, z: number, relativeTo?: Transform.Space): Transform; + } + + export module Transform { + export enum Space { + Self, + World + } + } +} From 8d14188c4c91006d80961065ca3080decf166b48 Mon Sep 17 00:00:00 2001 From: Vincent Siao Date: Fri, 11 Nov 2016 13:23:35 -0800 Subject: [PATCH 10/12] Revert "Update react-dnd typings to support decorators." --- react-dnd/react-dnd-decorator-tests.ts | 313 ------------------------- react-dnd/react-dnd.d.ts | 12 +- 2 files changed, 6 insertions(+), 319 deletions(-) delete mode 100644 react-dnd/react-dnd-decorator-tests.ts diff --git a/react-dnd/react-dnd-decorator-tests.ts b/react-dnd/react-dnd-decorator-tests.ts deleted file mode 100644 index 1d7c4b8d18..0000000000 --- a/react-dnd/react-dnd-decorator-tests.ts +++ /dev/null @@ -1,313 +0,0 @@ -/// -/// -/// -"use strict"; - -// Test adapted from the ReactDnD chess game tutorial: -// http://gaearon.github.io/react-dnd/docs-tutorial.html - -import React = require("react"); -import ReactDnd = require("react-dnd"); - -var r = React.DOM; - -import DragSource = ReactDnd.DragSource; -import DropTarget = ReactDnd.DropTarget; -import DragLayer = ReactDnd.DragLayer; -import DragDropContext = ReactDnd.DragDropContext; -import HTML5Backend, { getEmptyImage, NativeTypes } from "react-dnd-html5-backend"; -import TestBackend from "react-dnd-test-backend"; - -// Game Component -// ---------------------------------------------------------------------- - -namespace Game { - var knightPosition = [0, 0]; - var observer: any = null; - - function emitChange() { - observer(knightPosition); - } - - export function observe(o: any) { - if (observer) { - throw new Error("Multiple observers not implemented."); - } - - observer = o; - emitChange(); - } - - export function moveKnight(toX: number, toY: number) { - knightPosition = [toX, toY]; - emitChange(); - } - - export function canMoveKnight(toX: number, toY: number) { - const x = knightPosition[0]; - const y = knightPosition[1]; - const dx = toX - x; - const dy = toY - y; - - return (Math.abs(dx) === 2 && Math.abs(dy) === 1) || - (Math.abs(dx) === 1 && Math.abs(dy) === 2); - } -} - -var ItemTypes = { - KNIGHT: "knight" -}; - -// Knight Component -// ---------------------------------------------------------------------- - -namespace Knight { - interface KnightP extends React.Props { - connectDragSource: ReactDnd.ConnectDragSource; - connectDragPreview: ReactDnd.ConnectDragPreview; - isDragging: boolean; - } - - var knightSource: ReactDnd.DragSourceSpec = { - beginDrag: (props) => { - return {}; - } - }; - - function knightCollect(connect: ReactDnd.DragSourceConnector, monitor: ReactDnd.DragSourceMonitor) { - return { - connectDragSource: connect.dragSource(), - connectDragPreview: connect.dragPreview(), - isDragging: monitor.isDragging() - }; - } - - @DragSource(ItemTypes.KNIGHT, knightSource, knightCollect) - export class Knight extends React.Component { - static defaultProps: KnightP; - - static create = React.createFactory(Knight); - - componentDidMount() { - var img = getEmptyImage(); - img.onload = () => this.props.connectDragPreview(img); - } - - render() { - return this.props.connectDragSource( - r.div({ - style: { - opacity: this.props.isDragging ? 0.5 : 1, - fontSize: 25, - fontWeight: 'bold', - cursor: 'move' - } - }, "♘") - ); - } - } - - export var create = React.createFactory(Knight); -} - -// Square Component -// ---------------------------------------------------------------------- - -namespace Square { - interface SquareP extends React.Props { - black: boolean; - } - - export class Square extends React.Component { - render() { - var fill = this.props.black ? 'black' : 'white'; - return r.div({ - style: { - backgroundColor: fill - } - }) - } - } - - export var create = React.createFactory(Square); -} - -// BoardSquare Component -// ---------------------------------------------------------------------- - -namespace BoardSquare { - interface BoardSquareP extends React.Props { - x: number; - y: number; - connectDropTarget?: ReactDnd.ConnectDropTarget; - isOver?: boolean; - canDrop?: boolean; - } - - var boardSquareTarget: ReactDnd.DropTargetSpec = { - canDrop: (props) => Game.canMoveKnight(props.x, props.y), - drop: (props) => Game.moveKnight(props.x, props.y) - }; - - function boardSquareCollect(connect: ReactDnd.DropTargetConnector, monitor: ReactDnd.DropTargetMonitor) { - return { - connectDropTarget: connect.dropTarget(), - isOver: monitor.isOver(), - canDrop: monitor.canDrop() - }; - } - - @DropTarget(ItemTypes.KNIGHT, boardSquareTarget, boardSquareCollect) - @DropTarget(NativeTypes.FILE, boardSquareTarget, boardSquareCollect) - export class BoardSquare extends React.Component { - static defaultProps: BoardSquareP; - - private _renderOverlay = (color: string) => { - return r.div({ - style: { - position: 'absolute', - top: 0, - left: 0, - height: '100%', - width: '100%', - zIndex: 1, - opacity: 0.5, - backgroundColor: color - } - }); - }; - - render() { - var black = (this.props.x + this.props.y) % 2 === 1; - var isOver = this.props.isOver; - var canDrop = this.props.canDrop; - - return this.props.connectDropTarget( - r.div({ - style: { - position: 'relative', - width: '100%', - height: '100%' - }, - children: [ - Square.create({ - black: black - }), - isOver && !canDrop ? this._renderOverlay('red') : null, - !isOver && canDrop ? this._renderOverlay('yellow') : null, - isOver && canDrop ? this._renderOverlay('green') : null - ] - }) - ); - } - } - - export var create = React.createFactory(BoardSquare); -} - -// Custom Drag Layer Component -// ---------------------------------------------------------------------- -namespace CustomDragLayer { - interface CustomDragLayerP extends React.Props { - isDragging?: boolean; - item?: Object; - } - - function dragLayerCollect(monitor: ReactDnd.DragLayerMonitor) { - return { - isDragging: monitor.isDragging(), - item: monitor.getItem(), - }; - } - - @DragLayer(dragLayerCollect) - export class CustomDragLayer extends React.Component { - render() { - return r.div(null, this.props.isDragging ? this.props.item : null); - } - } - - export var create = React.createFactory(CustomDragLayer); -} - -// Board Component -// ---------------------------------------------------------------------- - -namespace Board { - interface BoardP extends React.Props { - knightPosition: number[]; - } - - export class Board extends React.Component { - private _renderPiece = (x: number, y: number) => { - var knightX = this.props.knightPosition[0]; - var knightY = this.props.knightPosition[1]; - return x === knightX && y === knightY ? - Knight.create() : - null; - }; - - private _renderSquare = (i: number) => { - var x = i % 8; - var y = Math.floor(i / 8); - - return r.div({ - key: i, - style: { - width: '12.5%', - height: '12.5%' - } - }, BoardSquare.create({ - x: x, - y: y - }, this._renderPiece(x, y))); - }; - - render() { - var squares: React.ReactHTMLElement[] = []; - for (let i = 0; i < 64; i++) { - squares.push(this._renderSquare(i)); - } - - return r.div({ - children: [ - CustomDragLayer.create(), - r.div({ - style: { - width: '100%', - height: '100%', - display: 'flex', - flexWrap: 'wrap' - }, - children: squares - }) - ] - }); - } - } - - @DragDropContext(HTML5Backend) - export class BoardWithHTML5Backend extends Board { - - } - - @DragDropContext(TestBackend) - export class BoardWithTestBackend extends Board { - - } - - export var createWithHTMLBackend = React.createFactory(BoardWithHTML5Backend); - export var createWithTestBackend = React.createFactory(BoardWithTestBackend); -} - -// Render the Board Component -// ---------------------------------------------------------------------- - -Board.createWithHTMLBackend({ - knightPosition: [0, 0] -}); - - -Board.createWithTestBackend({ - knightPosition: [0, 0] -}); diff --git a/react-dnd/react-dnd.d.ts b/react-dnd/react-dnd.d.ts index 37f065ec48..000cd04ee2 100644 --- a/react-dnd/react-dnd.d.ts +++ b/react-dnd/react-dnd.d.ts @@ -11,13 +11,13 @@ declare module __ReactDnd { // Decorated React Components // ---------------------------------------------------------------------- - interface ContextComponent extends React.Component { + class ContextComponent extends React.Component { getDecoratedComponentInstance(): React.Component; // Note: getManager is not yet documented on the React DnD docs. getManager(): any; } - interface DndComponent extends React.Component { + class DndComponent extends React.Component { getDecoratedComponentInstance(): React.Component; getHandlerId(): Identifier; } @@ -40,23 +40,23 @@ declare module __ReactDnd { spec: DragSourceSpec

, collect: DragSourceCollector, options?: DndOptions

- ): | React.StatelessComponent

>(componentClass: C) => C & DndComponentClass

; + ): (componentClass: React.ComponentClass

| React.StatelessComponent

) => DndComponentClass

; export function DropTarget

( types: Identifier | Identifier[] | ((props: P) => Identifier | Identifier[]), spec: DropTargetSpec

, collect: DropTargetCollector, options?: DndOptions

- ): | React.StatelessComponent

>(componentClass: C) => C & DndComponentClass

; + ): (componentClass: React.ComponentClass

| React.StatelessComponent

) => DndComponentClass

; export function DragDropContext

( backend: Backend - ): | React.StatelessComponent

>(componentClass: C) => C & ContextComponentClass

; + ):

(componentClass: React.ComponentClass

| React.StatelessComponent

) => ContextComponentClass

; export function DragLayer

( collect: DragLayerCollector, options?: DndOptions

- ): | React.StatelessComponent

>(componentClass: C) => C & DndComponentClass

; + ): (componentClass: React.ComponentClass

| React.StatelessComponent

) => DndComponentClass

; type DragSourceCollector = (connect: DragSourceConnector, monitor: DragSourceMonitor) => Object; type DropTargetCollector = (connect: DropTargetConnector, monitor: DropTargetMonitor) => Object; From e2b13f3c9ea99d7a9be6ba1fb26b6afb54a48ea8 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 31 Oct 2016 14:26:35 -0700 Subject: [PATCH 11/12] Change instructions for how to test a new type definition --- README.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d3e6c0e27c..b291fbbe51 100644 --- a/README.md +++ b/README.md @@ -55,18 +55,25 @@ Before you share your improvement with the world, use it yourself. #### Test editing an exiting package To add new features you can use [module augmentation](http://www.typescriptlang.org/docs/handbook/declaration-merging.html). -You can also directly edit the types in `node_modules/@types/foo/index.d.ts`, -or copy them from there and paste inside of `declarations.d.ts` and follow the steps below. +You can also directly edit the types in `node_modules/@types/foo/index.d.ts`, or copy them from there and follow the steps below. #### Test a new package -* Add a new file `declarations.d.ts` to your project. -* Add it to the compilation, through `"includes"` or `"files"` in your [tsconfig](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html), -or through a `/// ` declaration in your code. -* Inside `declarations.d.ts`, write `declare module "foo" { }`, then write the module declaration inside. -* Test that your code works. -* *Then*, once you've tested your definitions, make a PR contributing the definition. +Add to your `tsconfig.json`: + +```json +"baseUrl": ".", +"paths": { + "*": ["types/*"] +} +``` + +(You can also use `src/types`.) +Create `types/foo/index.d.ts` containing declarations for the module "foo". +You should now be able import from `"foo"` in your code and it will route to the new type definition. +Then build *and* run the code to make sure your type definition actually corresponds to what happens at runtime. +Once you've tested your definitions with real code, make a PR contributing the definition by copying `types/foo` to `DefinitelyTyped/foo` and adding a `tsconfig.json` and `foo-tests.ts`. ### Make a pull request From 85608b4d2993bae825b47a87a5ec9f4d228a11ae Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 17 Nov 2016 07:53:15 -0800 Subject: [PATCH 12/12] Use baseUrl and typeRoots instead --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b291fbbe51..ab2080714b 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,8 @@ You can also directly edit the types in `node_modules/@types/foo/index.d.ts`, or Add to your `tsconfig.json`: ```json -"baseUrl": ".", -"paths": { - "*": ["types/*"] -} +"baseUrl": "types", +"typeRoots": ["types"], ``` (You can also use `src/types`.)