You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/install/jssh.d.ts

779 lines
16 KiB
TypeScript

/** 全局变量对象 */
declare var global: any;
/** 是否 self-contained 方式执行 */
declare const __selfcontained: boolean;
/** CPU数量 */
declare const __cpucount: number;
/** 操作系统类型darwin, freebsd, linux, windows */
declare const __os: string;
/** 处理器架构386, amd64, arm, s390x */
declare const __arch: string;
/** JSSH版本号 */
declare const __version: string;
/** JSSH二进制文件路径 */
declare const __bin: string;
/** 当前进程PID */
declare const __pid: number;
/** 临时文件目录 */
declare const __tmpdir: string;
/** 当前用户HOME目录 */
declare const __homedir: string;
/** 当前用户名 */
declare const __user: string;
/** 当前主机名 */
declare const __hostname: string;
/** 当前脚本目录名 */
declare var __dirname: string;
/** 当前脚本文件名 */
declare var __filename: string;
/** 当前命令行参数 */
declare const __args: string[];
/** 当前环境变量 */
declare const __env: Record<string, string>;
/** 最近一次执行命令输出的内容 */
declare const __output: string;
/** 最近一次执行命令输出内容的字节数 */
declare const __outputbytes: number;
/** 最近一次执行命令进程退出code */
declare const __code: number;
/** 已自动加载的全局脚本文件列表 */
declare const __globalfiles: string[];
/**
* CommonJS
* @param modulename
* @return
*/
// @ts-ignore
declare function require(modulename: string): any;
/**
* eval
* @param filename URL
* @param content
* @return
*/
declare function evalfile(filename: string, content?: string): any;
/**
*
* @param data
* @return
*/
declare function bytesize(data: string): number;
/**
*
*/
declare function stdin(): string;
/**
* Uint8Array
*/
declare function stdinbytes(): Uint8Array;
/**
*
* @param format %s
* @param args
* @return
*/
declare function format(format: any, ...args: any[]): string;
/**
*
* @param format %s
* @param args
* @return
*/
declare function print(format: any, ...args: any[]): boolean;
/**
*
* @param format %s
* @param args
* @return
*/
declare function println(format: any, ...args: any[]): boolean;
/**
* stdout
* @param message
* @return
*/
declare function stdoutlog(message: string): boolean;
/**
* stderr
* @param message
* @return
*/
declare function stderrlog(message: string): boolean;
/**
*
* @return
*/
declare function readline(): string;
/**
*
* @param milliseconds
* @return
*/
declare function sleep(milliseconds: number): number;
/**
* 退
* @param code 退code
*/
declare function exit(code?: number): void;
/**
* *.json,*.yaml,*.toml
* @param file
* @param format
* @return
*/
declare function loadconfig(
file: string,
format?: "json" | "yaml" | "toml"
): any;
/**
* base64
* @param data
* @return
*/
declare function base64encode(data: string): string;
/**
* base64
* @param data
* @return
*/
declare function base64decode(data: string): string;
/**
* MD5
* @param data
* @return
*/
declare function md5(data: string): string;
/**
* SHA1
* @param data
* @return
*/
declare function sha1(data: string): string;
/**
* SAH256
* @param data
* @return
*/
declare function sha256(data: string): string;
/**
*
* @param size
* @param chars ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
* @return
*/
declare function randomstring(size: number, chars?: string): string;
/**
* PHP date() https://locutus.io/php/datetime/date/
* @param format
* @param timestamp Date
* @return
*/
declare function formatdate(format: string, timestamp?: number | Date): string;
/**
*
* @param target
* @param src
* @return
*/
declare function deepmerge(target: any, src: any): any;
/**
*
* @param name
* @param value
* @return
*/
declare function setenv(name: string, value: string): boolean;
/**
*
* @param cmd
* @param env
* @param mode 0=pipe1={output}2=pipe{output}
* @return
*/
declare function exec(
cmd: string,
env?: Record<string, string>,
mode?: number
): ExecResult;
/**
* mode=1
* @param cmd
* @param env
* @return
*/
declare function exec1(cmd: string, env?: Record<string, string>): ExecResult;
/**
* mode=2
* @param cmd
* @param env
* @return
*/
declare function exec2(cmd: string, env?: Record<string, string>): ExecResult;
/**
*
* @param cmd
* @param env
* @param mode 0=pipe1={output}2=pipe{output}
* @return
*/
declare function bgexec(
cmd: string,
env?: Record<string, string>,
mode?: number
): ExecResult;
/**
*
* @param dir
* @return
*/
declare function chdir(dir: string): boolean;
/**
*
* @param dir
* @return
*/
declare function cd(dir: string): boolean;
/**
*
* @return
*/
declare function cwd(): string;
/**
*
* @return
*/
declare function pwd(): string;
/**
*
* @return
*/
declare function networkinterfaces(): Record<string, NetworkInterface>;
interface NetworkInterface {
index: number;
mac: string;
list: {
address: string;
netmask: string;
family: string;
cidr: string;
internal: boolean;
multicast: boolean;
unspecified: boolean;
}[];
}
/** 文件相关操作模块 */
declare const fs: FsModule;
/** 文件路径相关操作模块 */
declare const path: PathModule;
/** 命令行参数相关操作模块 */
declare const cli: CliModule;
/** HTTP相关操作模块 */
declare const http: HttpModule;
/** 日志相关操作模块 */
declare const log: LogModule;
/** SSH相关操作模块 */
declare const ssh: SshModule;
/** Socket相关操作模块 */
declare const socket: SocketModule;
interface FsModule {
/**
*
* @param path
* @return
*/
readdir(path: string): FileStat[];
/**
*
* @param path
* @return
*/
readfile(path: string): string;
/**
*
* @param path
* @return
*/
readfilebytes(path: string): Uint8Array;
/**
*
* @param path
* @return
*/
stat(path: string): FileStat;
/**
*
* @param path
* @return
*/
exist(path: string): boolean;
/**
*
* @param path
* @param data
* @return
*/
writefile(path: string, data: string | Uint8Array): boolean;
/**
*
* @param path
* @param data
* @return
*/
appendfile(path: string, data: string | Uint8Array): boolean;
}
interface FileStat {
/** 文件名 */
name: string;
/** 是否为目录 */
isdir: boolean;
/** 文件mode如0644 */
mode: number;
/** 文件最后修改秒时间戳 */
modtime: number;
/** 文件大小 */
size: number;
}
interface PathModule {
/**
*
* @param args
* @return
*/
join(...args: string[]): string;
/**
*
* @param path
* @return
*/
abs(path: string): string;
/**
*
* @param path
* @return
*/
base(path: string): string;
/**
*
* @param path
* @return
*/
ext(path: string): string;
/**
*
* @param path
* @return
*/
dir(path: string): string;
}
interface CliModule {
/**
*
* @param flag
* @return
*/
get(flag: string): string;
/**
*
* @param index
* @return
*/
get(index: number): string;
/**
* f,false,0
* @param flag
* @return
*/
bool(flag: string): boolean;
/**
* args
* @return
*/
args(): string[];
/**
* opts
* @return Map
*/
opts(): Record<string, string>;
/**
* Enter
* @param message
* @return
*/
prompt(message?: string): string;
/**
*
* @param name *
* @param callback
*/
subcommand(name: string, callback: () => void): void;
/**
*
*/
subcommandstart(): void;
}
interface HttpModule {
/**
* HTTP
* @param milliseconds
* @return
*/
timeout(milliseconds: number): number;
/**
* HTTP
* @param method
* @param url URL
* @param headers
* @param body
* @return
*/
request(
method: string,
url: String,
headers?: Record<string, string>,
body?: string
): HttpResponse;
/**
* HTTP
* @param url
* @param filename
* @return
*/
download(url: string, filename?: string): string;
/**
* HTTP GET
* @param url URL
* @param headers
* @return
*/
get(url: String, headers?: Record<string, string>): HttpResponse;
/**
* HTTP HEAD
* @param url URL
* @param headers
* @return
*/
head(url: String, headers?: Record<string, string>): HttpResponse;
/**
* HTTP OPTIONS
* @param url URL
* @param headers
* @return
*/
options(url: String, headers?: Record<string, string>): HttpResponse;
/**
* HTTP POST
* @param url URL
* @param headers
* @param body
* @return
*/
post(
url: String,
headers?: Record<string, string>,
body?: string
): HttpResponse;
/**
* HTTP PUT
* @param url URL
* @param headers
* @param body
* @return
*/
put(
url: String,
headers?: Record<string, string>,
body?: string
): HttpResponse;
/**
* HTTP DELETE
* @param url URL
* @param headers
* @param body
* @return
*/
delete(
url: String,
headers?: Record<string, string>,
body?: string
): HttpResponse;
}
interface HttpResponse {
/** 状态码 */
status: number;
/** 响应头 */
headers: Record<string, string | string[]>;
/** 响应体 */
body: string;
}
interface LogModule {
/**
*
* @param format %s
* @param args
* @return
*/
debug(format: any, ...args: any[]): boolean;
/**
*
* @param format %s
* @param args
* @return
*/
info(format: any, ...args: any[]): boolean;
/**
*
* @param format %s
* @param args
* @return
*/
warn(format: any, ...args: any[]): boolean;
/**
*
* @param format %s
* @param args
* @return
*/
error(format: any, ...args: any[]): boolean;
/**
*
* @param format %s
* @param args
* @return
*/
fatal(format: any, ...args: any[]): boolean;
}
interface ExecResult {
/**
* PID
*/
pid: number;
/**
* 退code
*/
code?: number;
/**
* combineOutput=true
*/
output?: string;
/**
* combineOutput=true
*/
outputbytes?: number;
}
interface SshModule {
/**
* SSH
* @param name
* @param value
* @return
*/
set(
name: "user" | "password" | "key" | "keypass" | "auth" | "timeout" | "port",
value: any
): boolean;
/**
*
* @param host
* @return
*/
open(host: string): boolean;
/**
*
* @return
*/
close(): boolean;
/**
*
* @param name
* @param value
* @return
*/
setenv(name: string, value: string): boolean;
/**
*
* @param cmd
* @param env
* @param mode 0=pipe1={output}2=pipe{output}
* @return
*/
exec(cmd: string, env?: Record<string, string>, mode?: number): SshExecResult;
/**
* mode=1
* @param cmd
* @param env
* @return
*/
exec1(cmd: string, env?: Record<string, string>): SshExecResult;
/**
* mode=2
* @param cmd
* @param env
* @return
*/
exec2(cmd: string, env?: Record<string, string>): SshExecResult;
/**
* TTY
* @param cmd
* @param env
* @return
*/
pty(cmd: string, env?: Record<string, string>): SshExecResult;
}
interface SshExecResult {
/**
* 退code
*/
code?: number;
/**
* combineOutput=true
*/
output?: string;
/**
* combineOutput=true
*/
outputbytes?: number;
}
interface SocketModule {
/**
*
* @param milliseconds
* @return
*/
timeout(milliseconds: number): number;
/**
* TCP
* @param host
* @param port
* @param data
* @return
*/
tcpsend(host: string, port: number, data: string): string;
/**
* TCP
* @param host
* @param port
* @return
*/
tcptest(host: string, port: number): boolean;
}
interface SqlExecResult {
lastInsertId: number;
rowsAffected: number;
}
/**
*
* @param ok
* @param message
*/
declare function assert(ok: boolean, message?: string);