From c7118e8c8fbf8a9efbf687e0beb42eb368af9bd6 Mon Sep 17 00:00:00 2001 From: Felix Plymouth Date: Fri, 22 Jun 2018 22:54:36 +0200 Subject: [PATCH 1/3] [@types/deluge] Add types for the deluge library --- types/deluge/deluge-tests.ts | 23 +++++++ types/deluge/index.d.ts | 126 +++++++++++++++++++++++++++++++++++ types/deluge/tsconfig.json | 22 ++++++ types/deluge/tslint.json | 1 + 4 files changed, 172 insertions(+) create mode 100644 types/deluge/deluge-tests.ts create mode 100644 types/deluge/index.d.ts create mode 100644 types/deluge/tsconfig.json create mode 100644 types/deluge/tslint.json diff --git a/types/deluge/deluge-tests.ts b/types/deluge/deluge-tests.ts new file mode 100644 index 0000000000..bed31f4a55 --- /dev/null +++ b/types/deluge/deluge-tests.ts @@ -0,0 +1,23 @@ +import * as deluge from "."; +import * as http from 'http'; + +const delugeInstance: deluge.Deluge = deluge("deluge-webui-api-url", "password"); + +delugeInstance.getHosts((error, result : deluge.Host[], response : http.ServerResponse) => { +}) + +delugeInstance.connect("id", (error, result : boolean, response : http.ServerResponse) => { +}) + +delugeInstance.add("magnet_link", "path", (error, result : boolean, response: http.ServerResponse ) => { +}) + +delugeInstance.getTorrentRecord((error, result : deluge.TorrentRecord, response : http.ServerResponse) => { +}) + +delugeInstance.isConnected((error, result : boolean, response : http.ServerResponse) => { +}) + +delugeInstance.setCookies({ "http://www.some-private-tracker.com/": "my_cookie1=xxx;my_cookie2=yyy;" }, + (error, result : boolean, response : http.ServerResponse) => { +}) \ No newline at end of file diff --git a/types/deluge/index.d.ts b/types/deluge/index.d.ts new file mode 100644 index 0000000000..ffe6e5bcfe --- /dev/null +++ b/types/deluge/index.d.ts @@ -0,0 +1,126 @@ +// Type definitions for deluge 1.7 +// Project: https://github.com/ginman86/deluge +// Definitions by: Felix Plymouth +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as http from "http"; + +export = deluge; + +declare function deluge(deluge_url: string, password: string): deluge.Deluge + +declare namespace deluge{ + + export interface Host { + id: string, + ip: string, + port: number, + status: string + } + + export interface DelugeStats { + upload_protocol_rate: number, + max_upload: number, + download_protocol_rate: number, + download_rate: number, + has_incoming_connections: boolean, + num_connections: number, + max_download: number, + upload_rate: number, + dht_nodes: number, + free_space: number, + max_num_connections: number + } + + export interface Torrent { + max_download_speed: number, + upload_payload_rate: number, + download_payload_rate: number, + num_peers: number, + ratio: number, + total_peers: number, + state: string, + max_upload_speed: number, + eta: number, + save_path: string, + progress: number, + time_added: number, + tracker_host: string, + total_uploaded: number, + total_done: number, + total_wanted: number, + total_seeds: number, + seeds_peers_ratio: number, + num_seeds: number, + name: string, + is_auto_managed: boolean, + queue: number, + distributed_copies: number + } + + export interface TorrentRecord { + stats: DelugeStats, + connected: boolean, + torrents: { + [key: string]: Torrent + }, + filters: { + state: [string, number][], + tracker_host: [string, number][] + } + } + + export interface DownloadOptions { + file_priorities: any[], + add_paused: boolean, + compact_allocation: boolean, + download_location: string, + max_connections: number, + max_download_speed: number, + max_upload_slots: number, + max_upload_speed: number, + prioritize_first_last_pieces: boolean + } + + export interface Deluge { + /** + * Add the torrent to Deluge + * @param magnet + * @param dlPath + * @param callback + */ + add(magnet: string, dlPath: string | DownloadOptions, callback: (error: string, result: boolean, response: http.ServerResponse) => void): void; + + /** + * Connect the WebUI to the wanted daemon + * @param hostID + * @param callback + */ + connect(hostID: string, callback: (error: string, result: boolean, response: http.ServerResponse) => void): void; + /** + * Get the list of all the hosts that the WebUI can connect to + * @param callback + */ + getHosts(callback: (error: string, result: Host[], response: http.ServerResponse) => void): void; + /** + * Get the list of all torrents and changing data that represents their status in the WebUI + * @param callback + */ + getTorrentRecord(callback: (error: string, result: TorrentRecord, response: http.ServerResponse) => void): void; + + /** + * Check if the WebUI is connected to a deamon. Return true or false as result of the callback. + * @param callback + */ + isConnected(callback: (error: string, result: boolean, response: http.ServerResponse) => void): void; + /** + * Set cookies in COOKIE_JAR, cookies is an object with urls as keys, example: + * {'http://example.org/': 'uid=1234;pass=xxxx;'} + * @object cookies + */ + setCookies(cookies: { [key: string]: string }, callback: (error: string, result: boolean, response: http.ServerResponse) => void): void; + + } +} \ No newline at end of file diff --git a/types/deluge/tsconfig.json b/types/deluge/tsconfig.json new file mode 100644 index 0000000000..07694931b9 --- /dev/null +++ b/types/deluge/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "deluge-tests.ts" + ] +} diff --git a/types/deluge/tslint.json b/types/deluge/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/deluge/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 8f30ba936c2cdeae8d04cacf85fb72ea31dad9fe Mon Sep 17 00:00:00 2001 From: Felix Plymouth Date: Fri, 22 Jun 2018 23:22:59 +0200 Subject: [PATCH 2/3] Formatting fixes --- types/deluge/deluge-tests.ts | 26 +++---- types/deluge/index.d.ts | 146 +++++++++++++++++------------------ types/deluge/tsconfig.json | 1 + 3 files changed, 85 insertions(+), 88 deletions(-) diff --git a/types/deluge/deluge-tests.ts b/types/deluge/deluge-tests.ts index bed31f4a55..9a35db9c9b 100644 --- a/types/deluge/deluge-tests.ts +++ b/types/deluge/deluge-tests.ts @@ -1,23 +1,23 @@ -import * as deluge from "."; +import * as deluge from "deluge"; import * as http from 'http'; const delugeInstance: deluge.Deluge = deluge("deluge-webui-api-url", "password"); -delugeInstance.getHosts((error, result : deluge.Host[], response : http.ServerResponse) => { -}) +delugeInstance.getHosts((error: string, result: deluge.Host[], response: http.ServerResponse) => { +}); -delugeInstance.connect("id", (error, result : boolean, response : http.ServerResponse) => { -}) +delugeInstance.connect("id", (error: string, result: boolean, response: http.ServerResponse) => { +}); -delugeInstance.add("magnet_link", "path", (error, result : boolean, response: http.ServerResponse ) => { -}) +delugeInstance.add("magnet_link", "path", (error: string, result: boolean, response: http.ServerResponse) => { +}); -delugeInstance.getTorrentRecord((error, result : deluge.TorrentRecord, response : http.ServerResponse) => { -}) +delugeInstance.getTorrentRecord((error: string, result: deluge.TorrentRecord, response: http.ServerResponse) => { +}); -delugeInstance.isConnected((error, result : boolean, response : http.ServerResponse) => { -}) +delugeInstance.isConnected((error: string, result: boolean, response: http.ServerResponse) => { +}); delugeInstance.setCookies({ "http://www.some-private-tracker.com/": "my_cookie1=xxx;my_cookie2=yyy;" }, - (error, result : boolean, response : http.ServerResponse) => { -}) \ No newline at end of file + (error: string, result: boolean, response: http.ServerResponse) => { +}); diff --git a/types/deluge/index.d.ts b/types/deluge/index.d.ts index ffe6e5bcfe..8ca69daedd 100644 --- a/types/deluge/index.d.ts +++ b/types/deluge/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for deluge 1.7 // Project: https://github.com/ginman86/deluge -// Definitions by: Felix Plymouth +// Definitions by: Felix Plymouth // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -9,90 +9,88 @@ import * as http from "http"; export = deluge; -declare function deluge(deluge_url: string, password: string): deluge.Deluge +declare function deluge(deluge_url: string, password: string): deluge.Deluge; -declare namespace deluge{ +declare namespace deluge { + interface Host { + id: string; + ip: string; + port: number; + status: string; + } - export interface Host { - id: string, - ip: string, - port: number, - status: string + interface DelugeStats { + upload_protocol_rate: number; + max_upload: number; + download_protocol_rate: number; + download_rate: number; + has_incoming_connections: boolean; + num_connections: number; + max_download: number; + upload_rate: number; + dht_nodes: number; + free_space: number; + max_num_connections: number; } - - export interface DelugeStats { - upload_protocol_rate: number, - max_upload: number, - download_protocol_rate: number, - download_rate: number, - has_incoming_connections: boolean, - num_connections: number, - max_download: number, - upload_rate: number, - dht_nodes: number, - free_space: number, - max_num_connections: number + + interface Torrent { + max_download_speed: number; + upload_payload_rate: number; + download_payload_rate: number; + num_peers: number; + ratio: number; + total_peers: number; + state: string; + max_upload_speed: number; + eta: number; + save_path: string; + progress: number; + time_added: number; + tracker_host: string; + total_uploaded: number; + total_done: number; + total_wanted: number; + total_seeds: number; + seeds_peers_ratio: number; + num_seeds: number; + name: string; + is_auto_managed: boolean; + queue: number; + distributed_copies: number; } - - export interface Torrent { - max_download_speed: number, - upload_payload_rate: number, - download_payload_rate: number, - num_peers: number, - ratio: number, - total_peers: number, - state: string, - max_upload_speed: number, - eta: number, - save_path: string, - progress: number, - time_added: number, - tracker_host: string, - total_uploaded: number, - total_done: number, - total_wanted: number, - total_seeds: number, - seeds_peers_ratio: number, - num_seeds: number, - name: string, - is_auto_managed: boolean, - queue: number, - distributed_copies: number - } - - export interface TorrentRecord { - stats: DelugeStats, - connected: boolean, + + interface TorrentRecord { + stats: DelugeStats; + connected: boolean; torrents: { - [key: string]: Torrent - }, + [key: string]: Torrent; + }; filters: { - state: [string, number][], - tracker_host: [string, number][] - } + state: Array<[string, number]>; + tracker_host: Array<[string, number]>; + }; } - - export interface DownloadOptions { - file_priorities: any[], - add_paused: boolean, - compact_allocation: boolean, - download_location: string, - max_connections: number, - max_download_speed: number, - max_upload_slots: number, - max_upload_speed: number, - prioritize_first_last_pieces: boolean + + interface DownloadOptions { + file_priorities: any[]; + add_paused: boolean; + compact_allocation: boolean; + download_location: string; + max_connections: number; + max_download_speed: number; + max_upload_slots: number; + max_upload_speed: number; + prioritize_first_last_pieces: boolean; } - - export interface Deluge { - /** + + interface Deluge { + /** * Add the torrent to Deluge * @param magnet * @param dlPath * @param callback */ add(magnet: string, dlPath: string | DownloadOptions, callback: (error: string, result: boolean, response: http.ServerResponse) => void): void; - /** * Connect the WebUI to the wanted daemon * @param hostID @@ -109,11 +107,10 @@ declare namespace deluge{ * @param callback */ getTorrentRecord(callback: (error: string, result: TorrentRecord, response: http.ServerResponse) => void): void; - /** * Check if the WebUI is connected to a deamon. Return true or false as result of the callback. * @param callback - */ + */ isConnected(callback: (error: string, result: boolean, response: http.ServerResponse) => void): void; /** * Set cookies in COOKIE_JAR, cookies is an object with urls as keys, example: @@ -121,6 +118,5 @@ declare namespace deluge{ * @object cookies */ setCookies(cookies: { [key: string]: string }, callback: (error: string, result: boolean, response: http.ServerResponse) => void): void; - } -} \ No newline at end of file +} diff --git a/types/deluge/tsconfig.json b/types/deluge/tsconfig.json index 07694931b9..05deb4bcb2 100644 --- a/types/deluge/tsconfig.json +++ b/types/deluge/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes" : true, "baseUrl": "../", "typeRoots": [ "../" From 110f886130bd51a029b3167b95f24cdd4a5beb62 Mon Sep 17 00:00:00 2001 From: Felix Plymouth Date: Sat, 23 Jun 2018 10:40:14 +0200 Subject: [PATCH 3/3] [@types/deluge] Fix Import statement type --- types/deluge/deluge-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/deluge/deluge-tests.ts b/types/deluge/deluge-tests.ts index 9a35db9c9b..2ba8088915 100644 --- a/types/deluge/deluge-tests.ts +++ b/types/deluge/deluge-tests.ts @@ -1,4 +1,4 @@ -import * as deluge from "deluge"; +import deluge = require("deluge"); import * as http from 'http'; const delugeInstance: deluge.Deluge = deluge("deluge-webui-api-url", "password");