nkisi
Version:
Command line client for linking to Web Agent lanes over the WARP protocol
209 lines • 9.21 kB
JavaScript
import { Arg, Opt, Cmd } from "@nkisi/args";
import { Recon } from "@nkisi/recon";
import { Uri } from "@nkisi/uri";
import * as client from "@nkisi/client";
function link(hostUri, nodeUri, laneUri, format) {
var downlink = client.downlink();
if (hostUri !== void 0) {
downlink = downlink.hostUri(hostUri);
}
if (nodeUri !== void 0) {
downlink = downlink.nodeUri(nodeUri);
}
if (laneUri !== void 0) {
downlink = downlink.laneUri(laneUri);
}
return downlink.keepSynced(true)
.onEvent(function (body) {
if (format === "json") {
console.log(JSON.stringify(body.toAny()));
}
else {
console.log(Recon.toString(body));
}
})
.didUnlink(function (downlink) {
downlink.close();
});
}
function runLink(args) {
link(args.host, args.node, args.lane, args.format).keepSynced(false).open();
}
function runSync(args) {
link(args.host, args.node, args.lane, args.format).open();
}
function runGet(args) {
link(args.host, args.node, args.lane, args.format)
.didSync(function (downlink) {
downlink.close();
})
.open();
}
function runReflect(args) {
var edgeUri = args.edge;
if (edgeUri) {
var meshUri = args.mesh;
var hostUri = args.host;
var nodeUri = args.node;
var laneUri = args.lane;
if (nodeUri) {
var metaNodeUri = void 0;
if (meshUri) {
metaNodeUri = Uri.parse("nkisi:meta:mesh").appendedPath(meshUri, "node", nodeUri);
}
else if (hostUri) {
metaNodeUri = Uri.parse("nkisi:meta:host").appendedPath(hostUri, "node", nodeUri);
}
else {
metaNodeUri = Uri.parse("nkisi:meta:node").appendedPath(nodeUri);
}
if (laneUri) {
metaNodeUri = metaNodeUri.appendedPath("lane", laneUri);
link(edgeUri, metaNodeUri, "linkStats", args.format).open();
}
else {
if ("link" in args) {
link(edgeUri, metaNodeUri, "linkStats", args.format).open();
}
else {
link(edgeUri, metaNodeUri, "routerStats", args.format).open();
}
}
}
else if (hostUri !== void 0) {
var metaNodeUri = void 0;
if (meshUri) {
metaNodeUri = Uri.parse("nkisi:meta:mesh").appendedPath(meshUri);
if (hostUri) {
metaNodeUri = metaNodeUri.appendedPath("host", hostUri);
}
}
else {
metaNodeUri = Uri.parse("nkisi:meta:host");
if (hostUri) {
metaNodeUri = metaNodeUri.appendedPath(hostUri);
}
}
if ("process" in args) {
link(edgeUri, metaNodeUri, "processStats", args.format).open();
}
else if ("system" in args) {
link(edgeUri, metaNodeUri, "systemStats", args.format).open();
}
else if ("data" in args) {
link(edgeUri, metaNodeUri, "dataStats", args.format).open();
}
else if ("router" in args) {
link(edgeUri, metaNodeUri, "routerStats", args.format).open();
}
else if ("link" in args) {
link(edgeUri, metaNodeUri, "linkStats", args.format).open();
}
else {
link(edgeUri, metaNodeUri, "hostStats", args.format).open();
}
}
else if (meshUri !== void 0) {
var metaNodeUri = Uri.parse("nkisi:meta:mesh");
if (meshUri) {
metaNodeUri = metaNodeUri.appendedPath(meshUri);
}
if ("process" in args) {
link(edgeUri, metaNodeUri, "processStats", args.format).open();
}
else if ("system" in args) {
link(edgeUri, metaNodeUri, "systemStats", args.format).open();
}
else if ("data" in args) {
link(edgeUri, metaNodeUri, "dataStats", args.format).open();
}
else if ("router" in args) {
link(edgeUri, metaNodeUri, "routerStats", args.format).open();
}
else if ("link" in args) {
link(edgeUri, metaNodeUri, "linkStats", args.format).open();
}
else {
link(edgeUri, metaNodeUri, "meshStats", args.format).open();
}
}
else {
if ("process" in args) {
link(edgeUri, "nkisi:meta:edge", "processStats", args.format).open();
}
else if ("system" in args) {
link(edgeUri, "nkisi:meta:edge", "systemStats", args.format).open();
}
else if ("data" in args) {
link(edgeUri, "nkisi:meta:edge", "dataStats", args.format).open();
}
else if ("link" in args) {
link(edgeUri, "nkisi:meta:edge", "linkStats", args.format).open();
}
else {
link(edgeUri, "nkisi:meta:edge", "routerStats", args.format).open();
}
}
}
}
function runReflectLog(args) {
}
var linkCmd = Cmd.create("link")
.withDesc("stream changes to a lane of a remote node")
.withOpt(Opt.create("host").withFlag("h").withArg("hostUri").withDesc("remote host to link"))
.withOpt(Opt.create("node").withFlag("n").withArg("nodeUri").withDesc("remote node to link"))
.withOpt(Opt.create("lane").withFlag("l").withArg("laneUri").withDesc("lane to link"))
.withOpt(Opt.create("format").withFlag("f").withArg("json|recon").withDesc("event output format"))
.withHelpCmd()
.onExec(runLink);
var syncCmd = Cmd.create("sync")
.withDesc("stream the current state and changes to a lane of a remote node")
.withOpt(Opt.create("host").withFlag("h").withArg("hostUri").withDesc("remote host to link"))
.withOpt(Opt.create("node").withFlag("n").withArg("nodeUri").withDesc("remote node to link"))
.withOpt(Opt.create("lane").withFlag("l").withArg("laneUri").withDesc("lane to link"))
.withOpt(Opt.create("format").withFlag("f").withArg("json|recon").withDesc("event output format"))
.withHelpCmd()
.onExec(runSync);
var getCmd = Cmd.create("get")
.withDesc("fetch the current state of a lane of a remote node")
.withOpt(Opt.create("host").withFlag("h").withArg("hostUri").withDesc("remote host to link"))
.withOpt(Opt.create("node").withFlag("n").withArg("nodeUri").withDesc("remote node to link"))
.withOpt(Opt.create("lane").withFlag("l").withArg("laneUri").withDesc("lane to link"))
.withOpt(Opt.create("format").withFlag("f").withArg("json|recon").withDesc("event output format"))
.withHelpCmd()
.onExec(runGet);
var reflectLogCmd = Cmd.create("log")
.withDesc("stream log events")
.withOpt(Opt.create("trace").withFlag("t").withDesc("stream trace log messages"))
.withOpt(Opt.create("debug").withFlag("d").withDesc("stream debug log messages"))
.withOpt(Opt.create("info").withFlag("i").withDesc("stream info log messages"))
.withOpt(Opt.create("warn").withFlag("w").withDesc("stream warning log messages"))
.withOpt(Opt.create("error").withFlag("e").withDesc("stream error log messages"))
.withHelpCmd()
.onExec(runReflectLog);
var reflectCmd = Cmd.create("reflect")
.withDesc("stream introspection metadata")
.withOpt(Opt.create("edge").withFlag("e").withArg("edgeUri").withDesc("endpoint to introspect"))
.withOpt(Opt.create("mesh").withFlag("m").withArg(Arg.create("meshUri").asOptional(true)).withDesc("introspect default or specified mesh"))
.withOpt(Opt.create("part").withFlag("p").withArg(Arg.create("partKey").asOptional(true)).withDesc("introspect default or specified partition"))
.withOpt(Opt.create("host").withFlag("h").withArg(Arg.create("hostUri").asOptional(true)).withDesc("introspect default or specified host"))
.withOpt(Opt.create("node").withFlag("n").withArg("nodeUri").withDesc("introspect specified node"))
.withOpt(Opt.create("lane").withFlag("l").withArg("laneUri").withDesc("introspect specified lane"))
.withOpt(Opt.create("link").withFlag("k").withDesc("introspect link behavior"))
.withOpt(Opt.create("router").withFlag("r").withDesc("introspect router behavior"))
.withOpt(Opt.create("data").withDesc("introspect data behavior"))
.withOpt(Opt.create("system").withDesc("introspect system behavior"))
.withOpt(Opt.create("process").withDesc("introspect process behavior"))
.withOpt(Opt.create("stats").withFlag("s").withDesc("stream introspection statistics"))
.withOpt(Opt.create("format").withFlag("f").withArg("json|recon").withDesc("event output format"))
.withCmd(reflectLogCmd)
.withHelpCmd()
.onExec(runReflect);
var cmd = Cmd.create("nkisi")
.withCmd(linkCmd)
.withCmd(syncCmd)
.withCmd(getCmd)
.withCmd(reflectCmd)
.withHelpCmd();
cmd.parse().run();
//# sourceMappingURL=index.js.map