From 7196075fbd9b6eaedeb3d675abaf3fced4a3a04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Ksi=C4=99ski?= Date: Thu, 30 Aug 2018 16:13:06 +0200 Subject: [PATCH] [jsftp] Add types for jsftp --- types/jsftp/index.d.ts | 50 ++++++++++++++++++++++++++++++++++++++ types/jsftp/jsftp-tests.ts | 25 +++++++++++++++++++ types/jsftp/tsconfig.json | 23 ++++++++++++++++++ types/jsftp/tslint.json | 1 + 4 files changed, 99 insertions(+) create mode 100644 types/jsftp/index.d.ts create mode 100644 types/jsftp/jsftp-tests.ts create mode 100644 types/jsftp/tsconfig.json create mode 100644 types/jsftp/tslint.json diff --git a/types/jsftp/index.d.ts b/types/jsftp/index.d.ts new file mode 100644 index 0000000000..ed543e5bb2 --- /dev/null +++ b/types/jsftp/index.d.ts @@ -0,0 +1,50 @@ +// Type definitions for jsftp 2.1 +// Project: https://github.com/sergi/jsftp +// Definitions by: Konrad Księski +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { Socket } from 'net'; +import { EventEmitter } from 'events'; + +export interface JsftpOpts { + host?: string; + port?: number; + user?: string; + pass?: string; + createSocket?: ({ port, host }: { port: number, host: string }, firstAction: () => {}) => Socket; + useList?: boolean; +} + +export type ErrorCallback = (err: Error) => void; +export type RawCallback = (err: Error, data: { code: number, text: string }) => void; +export type ListCallback = (err: Error, dirContents: string) => void; +export type GetCallback = (err: Error, socket: Socket) => void; +export type LsCallback = (err: Error, res: [{ name: string }]) => void; + +export default class Ftp extends EventEmitter { + constructor(opts: JsftpOpts); + + ls(filePath: string, callback: LsCallback): void; + + list(filePath: string, callback: ListCallback): void; + + get(remotePath: string, callback: GetCallback): void; + get(remotePath: string, localPath: string, callback: ErrorCallback): void; + + put(source: string | Buffer | NodeJS.ReadableStream, remotePath: string, callback: ErrorCallback): void; + + rename(from: string, to: string, callback: ErrorCallback): void; + + // Ftp.raw(command, params, callback) + raw(command: string, callback: RawCallback): void; + raw(command: string, arg1: any, callback: RawCallback): void; + raw(command: string, arg1: any, arg2: any, callback: RawCallback): void; + raw(command: string, arg1: any, arg2: any, arg3: any, callback: RawCallback): void; + raw(command: string, arg1: any, arg2: any, arg3: any, arg4: any, callback: RawCallback): void; + + keepAlive(timeInMs?: number): void; + + destroy(): void; +} diff --git a/types/jsftp/jsftp-tests.ts b/types/jsftp/jsftp-tests.ts new file mode 100644 index 0000000000..94ad47cbd4 --- /dev/null +++ b/types/jsftp/jsftp-tests.ts @@ -0,0 +1,25 @@ +import Ftp from 'jsftp'; + +const connectOpts = { + host: 'localhost', + port: 22222, +}; + +const ftp = new Ftp(connectOpts); // $ExpectType Ftp + +ftp.ls('foo', (err) => { }); // $ExpectType void + +ftp.list('foo', (err) => { }); // $ExpectType void + +ftp.get('foo', (err) => { }); // $ExpectType void +ftp.get('foo', 'bar', (err) => { }); // $ExpectType void + +ftp.put('foo', 'bar', (err) => { }); // $ExpectType void + +ftp.rename('foo', 'bar', (err) => { }); // $ExpectType void + +ftp.raw('foo', 'param', (err) => { }); // $ExpectType void + +ftp.keepAlive(); // $ExpectType void + +ftp.destroy(); // $ExpectType void diff --git a/types/jsftp/tsconfig.json b/types/jsftp/tsconfig.json new file mode 100644 index 0000000000..f5d841a4ef --- /dev/null +++ b/types/jsftp/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jsftp-tests.ts" + ] +} diff --git a/types/jsftp/tslint.json b/types/jsftp/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/jsftp/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }