adbkit typing

Summary: Adding proper types for adbkit (extracted from their documentation)

Reviewed By: passy

Differential Revision: D17342184

fbshipit-source-id: da0fc0264961ca3a0fa775ab5165d20872042eb8
This commit is contained in:
Daniel Büchele
2019-09-13 05:25:36 -07:00
committed by Facebook Github Bot
parent 01be3dc5d1
commit 4e7cf077b8
8 changed files with 144 additions and 168 deletions

View File

@@ -14,11 +14,58 @@ interface Util {
readAll: (stream: NodeJS.ReadStream) => Promise<Buffer>;
}
// https://github.com/openstf/adbkit#pulltransfer
interface PullTransfer extends NodeJS.WriteStream {
cancel: () => this;
on(
event: 'progress',
listener: (stats: {bytesTransferred: number}) => void,
): this;
on(event: 'error', listener: (err: Error) => void): this;
on(event: 'end', listener: () => void): this;
}
interface DeviceTracker extends NodeJS.EventEmitter {
on(event: 'add', listener: (device: Device) => void): this;
on(event: 'remove', listener: (device: Device) => void): this;
on(event: 'change', listener: (device: Device) => void): this;
on(
event: 'changeSet',
listener: (changes: {
added: Device[];
removed: Device[];
changed: Device[];
}) => void,
): this;
on(event: 'error', listener: (err: Error) => void): this;
on(event: 'end', listener: () => void): this;
}
declare module 'adbkit-fb' {
const util: Util;
const adbkit: any;
export interface Client {
listDevices: () => Promise<Device[]>;
reverse: (
serial: string,
remote: string,
local: string,
) => Promise<boolean>;
shell: (
serial: string,
command: string | string[],
) => Promise<NodeJS.ReadStream>;
screencap: (serial: string) => Promise<NodeJS.WriteStream>;
pull: (serial: string, path: string) => Promise<PullTransfer>;
openLogcat: (
serial: string,
options?: {
clear?: boolean;
},
) => Promise<import('adbkit-logcat-fb').Reader>;
getProperties: (serial: string) => Promise<{[key: string]: string}>;
trackDevices: () => Promise<DeviceTracker>;
kill: () => Promise<boolean>;
}
export function createClient(config: {port: number; host: string}): Client;
}

View File

@@ -1,127 +0,0 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
// This module declaration is a stub!
// Please extend this as needed.
declare module 'adbkit-logcat-fb' {
class Reader {
constructor(options: any);
connect(stream: any): any;
end(): any;
exclude(tag: any): any;
excludeAll(): any;
include(tag: any, priority: any): any;
includeAll(priority: any): any;
resetFilters(): any;
static ANY: string;
static defaultMaxListeners: number;
static init(): void;
static listenerCount(emitter: any, type: any): any;
static once(emitter: any, name: any): any;
static usingDomains: boolean;
}
function Priority(): void;
function readStream(stream: any, options: any): any;
namespace Priority {
const DEBUG: number;
const DEFAULT: number;
const ERROR: number;
const FATAL: number;
const INFO: number;
const SILENT: number;
const UNKNOWN: number;
const VERBOSE: number;
const WARN: number;
function fromLetter(letter: any): any;
function fromName(name: any): any;
function toLetter(value: any): any;
function toName(value: any): any;
}
namespace Reader {
class EventEmitter {
constructor();
addListener(type: any, listener: any): any;
emit(type: any, args: any): any;
eventNames(): any;
getMaxListeners(): any;
listenerCount(type: any): any;
listeners(type: any): any;
off(type: any, listener: any): any;
on(type: any, listener: any): any;
once(type: any, listener: any): any;
prependListener(type: any, listener: any): any;
prependOnceListener(type: any, listener: any): any;
rawListeners(type: any): any;
removeAllListeners(type: any, ...args: any[]): any;
removeListener(type: any, listener: any): any;
setMaxListeners(n: any): any;
static EventEmitter: any;
static defaultMaxListeners: number;
static init(): void;
static listenerCount(emitter: any, type: any): any;
static once(emitter: any, name: any): any;
static usingDomains: boolean;
}
}
}

View File

@@ -0,0 +1,66 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
// This module declaration is a stub!
// Please extend this as needed.
declare module 'adbkit-logcat-fb' {
type PriorityValue = number;
interface Reader extends NodeJS.EventEmitter {
connect(stream: NodeJS.WriteStream): this;
end(): this;
exclude(tag: string): this;
excludeAll(): this;
include(tag: string, priority?: PriorityValue): this;
includeAll(priority?: PriorityValue): this;
resetFilters(): this;
on(event: 'error', listener: (err: Error) => void): this;
on(event: 'end', listener: () => void): this;
on(event: 'finish', listener: () => void): this;
on(event: 'entry', listener: (entry: Entry) => void): this;
}
interface Entry {
date: Date;
pid: number;
tid: number;
priority: PriorityValue;
tag: string;
message: string;
toBinary(): Buffer;
}
interface Priority {
DEBUG: PriorityValue;
DEFAULT: PriorityValue;
ERROR: PriorityValue;
FATAL: PriorityValue;
INFO: PriorityValue;
SILENT: PriorityValue;
UNKNOWN: PriorityValue;
VERBOSE: PriorityValue;
WARN: PriorityValue;
fromLetter(letter: string): PriorityValue | undefined;
fromName(name: string): PriorityValue | undefined;
toLetter(value: PriorityValue): string;
toName(value: PriorityValue): string;
}
function readStream(
stream: NodeJS.WriteStream,
options?: {
format: 'binary';
fixLineFeeds: boolean;
},
): Reader;
const Priority: Priority;
const Reader: Reader;
}