cn-shell
Version:
Cloud Native Shell
160 lines (159 loc) • 4.22 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
import { Logger, LogLevel } from "./logger.js";
import { ShellExt, ShellExtConfig } from "./shell-ext.js";
import { ConfigMan, ConfigTypes, ConfigOptions } from "./config-man.js";
import shelljs from "shelljs";
import { Pool } from "undici";
import * as undici from "undici";
import * as http from "node:http";
export {
Logger,
LogLevel,
ShellExt,
ShellExtConfig,
ConfigMan,
ConfigTypes,
ConfigOptions,
undici,
};
export interface ShellConfig {
name: string;
appVersion?: string;
log?: {
logger?: Logger;
level?: string;
timestamp?: boolean;
timestampFormat?: string;
};
http?: {
keepAliveTimeout?: number;
headerTimeout?: number;
healthcheckPort?: number;
healthcheckInterface?: string;
healthcheckPath?: string;
healthcheckGoodRes?: number;
healthcheckBadRes?: number;
};
}
export interface QuestionOptions {
muteAnswer?: boolean;
muteChar?: string;
}
export interface HttpReqPoolOptions extends Pool.Options {}
export interface HttpReqResponse {
statusCode: number;
headers: {
[key: string]: string | string[] | undefined;
};
trailers: {
[key: string]: string;
};
body: string | object;
}
export interface HttpReqOptions {
method: "GET" | "PUT" | "POST" | "DELETE" | "PATCH";
searchParams?: {
[key: string]: string | string[];
};
headers?: {
[key: string]: string;
};
body?: object | string;
auth?: {
username: string;
password: string;
};
bearerToken?: string;
}
export declare class Shell {
private readonly _name;
private readonly _appVersion;
private _configMan;
private _logger;
private _httpKeepAliveTimeout;
private _httpHeaderTimeout;
private _healthcheckPort;
private _healthcheckInterface;
private _healthCheckPath;
private _healthCheckGoodResCode;
private _healthCheckBadResCode;
private _healthcheckServer?;
private _exts;
private _httpReqPools;
cat: shelljs.CatFunction;
cd: typeof shelljs.cd;
chmod: shelljs.ChmodFunction;
cp: shelljs.CopyFunction;
dirs: shelljs.DirsFunction;
echo: shelljs.EchoFunction;
env: NodeJS.ProcessEnv;
testError: typeof shelljs.error;
exec: shelljs.ExecFunction;
find: shelljs.FindFunction;
grep: shelljs.GrepFunction;
head: shelljs.HeadFunction;
ln: shelljs.LinkFunction;
ls: shelljs.ListFunction;
mkdir: shelljs.MkdirFunction;
mv: shelljs.MoveFunction;
popd: shelljs.PopDirFunction;
pushd: shelljs.PushDirFunction;
pwd: typeof shelljs.pwd;
rm: shelljs.RemoveFunction;
sed: shelljs.SedFunction;
set: typeof shelljs.set;
sort: shelljs.SortFunction;
tail: shelljs.TailFunction;
tempdir: typeof shelljs.tempdir;
touch: shelljs.TouchFunction;
uniq: shelljs.UniqFunction;
constructor(passedConfig: ShellConfig);
protected start(): Promise<boolean>;
protected stop(): Promise<void>;
protected healthCheck(): Promise<boolean>;
get name(): string;
get appVersion(): string;
get logger(): Logger;
set level(level: LogLevel);
private setupHealthcheck;
private startupError;
init(testing?: boolean): Promise<void>;
exit(code: number, hard?: boolean): Promise<void>;
getConfigStr(
config: string,
passedOptions?: ConfigOptions,
appOrExtName?: string,
): string;
getConfigBool(
config: string,
passedOptions?: ConfigOptions,
appOrExtName?: string,
): boolean;
getConfigNum(
config: string,
passedOptions?: ConfigOptions,
appOrExtName?: string,
): number;
healthcheckCallback(
req: http.IncomingMessage,
res: http.ServerResponse,
): Promise<void>;
fatal(...args: any): void;
error(...args: any): void;
warn(...args: any): void;
info(...args: any): void;
startup(...args: any): void;
debug(...args: any): void;
trace(...args: any): void;
force(...args: any): void;
addExt(ext: ShellExt): void;
sleep(durationInSeconds: number): Promise<void>;
question(ask: string, passedOptions?: QuestionOptions): Promise<string>;
createHttpReqPool(origin: string, passedOptions?: HttpReqPoolOptions): void;
httpReq(
origin: string,
path: string,
passedOptions?: HttpReqOptions,
): Promise<HttpReqResponse>;
}