mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
node-ssh: initial definition (#42964)
This commit is contained in:
87
types/node-ssh/index.d.ts
vendored
Normal file
87
types/node-ssh/index.d.ts
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
// Type definitions for node-ssh 7.0
|
||||
// Project: https://github.com/steelbrain/node-ssh
|
||||
// Definitions by: Junxiao Shi <https://github.com/yoursunny>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { ClientChannel, ExecOptions as ssh2ExecOptions, SFTPWrapper } from "ssh2";
|
||||
import { TransferOptions } from "ssh2-streams";
|
||||
|
||||
declare namespace SSH {
|
||||
type Shell = ClientChannel;
|
||||
type SFTP = SFTPWrapper;
|
||||
|
||||
interface ConfigGiven {
|
||||
host: string;
|
||||
port?: number;
|
||||
username: string;
|
||||
password?: string;
|
||||
privateKey?: string;
|
||||
onKeyboardInteractive?: () => void | boolean;
|
||||
}
|
||||
|
||||
interface ExecOptions {
|
||||
cwd?: string;
|
||||
stdin?: string;
|
||||
options?: ssh2ExecOptions;
|
||||
onStdout?: (chunk: Buffer) => void;
|
||||
onStderr?: (chunk: Buffer) => void;
|
||||
}
|
||||
|
||||
interface ExecResult {
|
||||
stdout: string;
|
||||
stderr: string;
|
||||
code: number;
|
||||
signal?: string;
|
||||
}
|
||||
|
||||
interface PutFilesOptions {
|
||||
sftp?: SFTP;
|
||||
sftpOptions?: TransferOptions;
|
||||
concurrency?: number;
|
||||
}
|
||||
|
||||
interface PutDirectoryOptions {
|
||||
sftp?: SFTP;
|
||||
sftpOptions?: TransferOptions;
|
||||
concurrency?: number;
|
||||
recursive?: boolean;
|
||||
tick?: (localPath: string, remotePath: string, error: Error | null | undefined) => void;
|
||||
validate?: (localPath: string) => boolean;
|
||||
}
|
||||
}
|
||||
|
||||
declare class SSH {
|
||||
constructor();
|
||||
|
||||
connect(givenConfig: SSH.ConfigGiven): Promise<this>;
|
||||
|
||||
requestShell(): Promise<SSH.Shell>;
|
||||
|
||||
requestSFTP(): Promise<SSH.SFTP>;
|
||||
|
||||
mkdir(path: string, type: "exec"): Promise<void>;
|
||||
|
||||
mkdir(path: string, type?: "sftp", givenSftp?: SSH.SFTP): Promise<void>;
|
||||
|
||||
exec(command: string, parameters?: ReadonlyArray<string>,
|
||||
options?: SSH.ExecOptions & { stream?: "stdout"|"stderr" }): Promise<string>;
|
||||
|
||||
exec(command: string, parameters?: ReadonlyArray<string>,
|
||||
options?: SSH.ExecOptions & { stream: "both" }): Promise<SSH.ExecResult>;
|
||||
|
||||
execCommand(givenCommand: string, options?: SSH.ExecOptions): Promise<SSH.ExecResult>;
|
||||
|
||||
getFile(localFile: string, remoteFile: string, givenSftp?: SSH.SFTP, givenOpts?: TransferOptions): Promise<void>;
|
||||
|
||||
putFile(localFile: string, remoteFile: string, givenSftp?: SSH.SFTP, givenOpts?: TransferOptions): Promise<void>;
|
||||
|
||||
putFiles(files: ReadonlyArray<{ local: string, remote: string }>, givenConfig?: SSH.PutFilesOptions): Promise<void>;
|
||||
|
||||
putDirectory(localDirectory: string, remoteDirectory: string, givenConfig?: SSH.PutDirectoryOptions): Promise<boolean>;
|
||||
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
export = SSH;
|
||||
32
types/node-ssh/node-ssh-tests.ts
Normal file
32
types/node-ssh/node-ssh-tests.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import SSH = require("node-ssh");
|
||||
|
||||
const client = new SSH();
|
||||
client.connect({
|
||||
host: "127.0.0.1",
|
||||
username: "steel",
|
||||
password: "password",
|
||||
})
|
||||
.then(async (client) => {
|
||||
// $ExpectType SSH
|
||||
client;
|
||||
|
||||
// $ExpectType string
|
||||
await client.exec("pwd", [], { cwd: "/etc" });
|
||||
// $ExpectType string
|
||||
await client.exec("pwd", [], { stream: "stderr" });
|
||||
// $ExpectType ExecResult
|
||||
await client.exec("pwd", [], { stream: "both" });
|
||||
// $ExpectType ExecResult
|
||||
await client.execCommand("node");
|
||||
|
||||
await client.requestShell();
|
||||
const sftp = await client.requestSFTP();
|
||||
|
||||
await client.mkdir("/root");
|
||||
await client.mkdir("/root", "exec");
|
||||
await client.mkdir("/root", "sftp", sftp);
|
||||
await client.getFile("1.txt", "1.txt", sftp);
|
||||
await client.putFile("1.txt", "1.txt", sftp);
|
||||
await client.putFiles([{ local: "1.txt", remote: "1.txt" }], { sftp });
|
||||
await client.putDirectory("/root", "/root", { sftp });
|
||||
});
|
||||
23
types/node-ssh/tsconfig.json
Normal file
23
types/node-ssh/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"node-ssh-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/node-ssh/tslint.json
Normal file
1
types/node-ssh/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user