diff --git a/packages/controller/controller.ts b/packages/controller/controller.ts index e0e72c0f..2d9a849f 100644 --- a/packages/controller/controller.ts +++ b/packages/controller/controller.ts @@ -32,7 +32,7 @@ const { ConsoleTransport, levels, logger } = lib; import Controller from "./src/Controller"; import UserManager from "./src/UserManager"; -const version = require("./package.json").version; +import { version } from "./package.json"; // globals let controller: Controller; diff --git a/packages/controller/src/ControlConnection.ts b/packages/controller/src/ControlConnection.ts index 58eb0fd1..b416b0f0 100644 --- a/packages/controller/src/ControlConnection.ts +++ b/packages/controller/src/ControlConnection.ts @@ -29,17 +29,13 @@ export default class ControlConnection extends BaseConnection { private _agent: string; private _version: string; logTransport: lib.LinkTransport | null = null; - logSubscriptions: { - all: boolean, - controller: boolean, - hostIds: number[], - instanceIds: number[], - } = { + logSubscriptions = { all: false, controller: false, - hostIds: [], - instanceIds: [], + hostIds: [] as number[], + instanceIds: [] as number[], }; + ws_dumper: ((...args: any[]) => void) | null = null; declare connector: WsServerConnector; diff --git a/packages/controller/src/Controller.ts b/packages/controller/src/Controller.ts index 900ebce5..9951fb9b 100644 --- a/packages/controller/src/Controller.ts +++ b/packages/controller/src/Controller.ts @@ -1,13 +1,10 @@ import type winston from "winston"; import type { AddressInfo } from "net"; import type { ControllerArgs } from "../controller"; -import type { HostInfo } from "./HostConnection"; -import type { Request, Response, Application } from "express"; - +import express, { type Request, type Response, type NextFunction, type Application } from "express"; import compression from "compression"; import events, { EventEmitter } from "events"; -import express from "express"; import fs from "fs-extra"; import http from "http"; import https from "https"; @@ -20,12 +17,11 @@ const { logger, Summary, Gauge } = lib; import HttpCloser from "./HttpCloser"; import InstanceInfo, { InstanceStatus } from "./InstanceInfo"; -import metrics from "./metrics"; +import * as metrics from "./metrics"; import * as routes from "./routes"; import UserManager from "./UserManager"; import WsServer from "./WsServer"; -import yargs from "yargs"; -import HostConnection from "./HostConnection"; +import HostConnection, { type HostInfo } from "./HostConnection"; const endpointDurationSummary = new Summary( "clusterio_controller_http_endpoint_duration_seconds", @@ -176,7 +172,8 @@ export default class Controller { const webpackConfigs = []; if (args.dev) { - webpackConfigs.push(require("../../../webpack.config")({})); + // eslint-disable-next-line node/no-missing-require + webpackConfigs.push(require("../../../webpack.config")({})); // Path outside of build } if (args.devPlugin) { let devPlugins = new Map(); @@ -882,8 +879,7 @@ export default class Controller { ControllerPluginClass = await lib.loadControllerPluginClass(pluginInfo); } - //@ts-ignore //TODO::: metrics is lib.Counter but ControllerPluginClass expect any[], can't figure out how the metrics is used. - let controllerPlugin = new ControllerPluginClass(pluginInfo, this, metrics, logger); + let controllerPlugin = new ControllerPluginClass(pluginInfo, this, metrics as any, logger); await controllerPlugin.init(); this.plugins.set(pluginInfo.name, controllerPlugin); @@ -950,8 +946,8 @@ export default class Controller { /** * Servers the web interface with the root path set apropriately * - * @param {string} route - route the interface is served under. - * @returns {function} Experess.js route handler. + * @param route - route the interface is served under. + * @returns Experess.js route handler. */ static serveWeb(route: string) { // The depth is is the number of slashes in the route minus one, but due @@ -959,7 +955,7 @@ export default class Controller { // compensate if the request path contains a slash but not the route, // and vice versa. let routeDepth = (route.match(/\//g) || []).length - 1 - Number(route.slice(-1) === "/"); - return function(req: Request, res: Response, next: Function) { + return function(req: Request, res: Response, next: NextFunction) { let depth = routeDepth + Number(req.path.slice(-1) === "/"); let webRoot = "../".repeat(depth) || "./"; let staticRoot = webRoot; diff --git a/packages/controller/src/HostConnection.ts b/packages/controller/src/HostConnection.ts index 61d2fb97..76a7019b 100644 --- a/packages/controller/src/HostConnection.ts +++ b/packages/controller/src/HostConnection.ts @@ -13,7 +13,7 @@ export interface HostInfo { id: number; name: string; version: string; - plugins: [number, any][]; + plugins: Record; public_address: string | undefined; token_valid_after?: number; } @@ -30,10 +30,10 @@ export default class HostConnection extends BaseConnection { private _id: any; private _name: any; private _version: any; - plugins: Map; + plugins: Map; constructor( - registerData: any, + registerData: lib.RegisterHostData, connector: WsServerConnector, controller: Controller, ) { diff --git a/packages/controller/src/InstanceInfo.ts b/packages/controller/src/InstanceInfo.ts index 40c869cb..e33f43f3 100644 --- a/packages/controller/src/InstanceInfo.ts +++ b/packages/controller/src/InstanceInfo.ts @@ -36,7 +36,7 @@ export default class InstanceInfo { this.status = status; } - toJSON(): Object { + toJSON() { return { config: this.config.serialize(), status: this.status, diff --git a/packages/controller/src/WsServer.ts b/packages/controller/src/WsServer.ts index 07886741..333c06fb 100644 --- a/packages/controller/src/WsServer.ts +++ b/packages/controller/src/WsServer.ts @@ -12,7 +12,7 @@ import ControlConnection from "./ControlConnection"; import HostConnection, { HostInfo } from "./HostConnection"; import WsServerConnector from "./WsServerConnector"; -const packageVersion = require("../package.json").version; +import { version as packageVersion } from "../package.json"; const wsMessageCounter = new lib.Counter( "clusterio_controller_websocket_message_total", @@ -111,12 +111,11 @@ export default class WsServer { } }); let originalSend = socket.send; - socket.send = (...args: any[]) => { + socket.send = (...args: [string, any]) => { wsMessageCounter.labels("out").inc(); if (typeof args[0] === "string" && !socket.clusterio_ignore_dump) { this.controller.debugEvents.emit("message", { direction: "out", content: args[0] }); } - // @ts-ignore TODO::: Issue with originalSend having multiple signatures ? return originalSend.call(socket, ...args); }; diff --git a/packages/controller/src/metrics.ts b/packages/controller/src/metrics.ts index ae0b7aca..b588be00 100644 --- a/packages/controller/src/metrics.ts +++ b/packages/controller/src/metrics.ts @@ -1,7 +1,7 @@ import * as lib from "@clusterio/lib"; import util from "util"; -const endpointHitCounter = new lib.Counter( +export const endpointHitCounter = new lib.Counter( "clusterio_controller_http_endpoint_hits_total", "How many requests a particular HTTP endpoint has gotten", { labels: ["route"], register: false } @@ -11,5 +11,3 @@ endpointHitCounter.labels = util.deprecate( endpointHitCounter.labels, "incrementing endpointHitCounter is no longer needed and has no effect" ); - -export default endpointHitCounter; diff --git a/packages/controller/src/routes.ts b/packages/controller/src/routes.ts index 4e5c14a1..3f9f6adc 100644 --- a/packages/controller/src/routes.ts +++ b/packages/controller/src/routes.ts @@ -61,7 +61,7 @@ async function getMetrics(req: Request, res: Response, next: any) { )); } - for await (let result of await lib.defaultRegistry.collect()) { + for await (let result of lib.defaultRegistry.collect()) { results.push(result); } diff --git a/packages/ctl/src/commands.ts b/packages/ctl/src/commands.ts index 484490f1..5ab0da5f 100644 --- a/packages/ctl/src/commands.ts +++ b/packages/ctl/src/commands.ts @@ -89,7 +89,7 @@ const controllerConfigCommands = new lib.CommandTree({ controllerConfigCommands.add(new lib.Command({ definition: ["list", "List controller configuration"], - handler: async function(args: {}, control: Control) { + handler: async function(args: object, control: Control) { let response = await control.send(new lib.ControllerConfigGetRequest()); for (let group of (response.serializedConfig as any).groups) { @@ -212,13 +212,13 @@ const controllerPluginCommands = new lib.CommandTree({ }); controllerPluginCommands.add(new lib.Command({ definition: ["list", "List plugins on controller"], - handler: async function(args: {}, control: Control) { + handler: async function(args: object, control: Control) { let url = new URL(control.config.get("control.controller_url") as string); url.pathname += "api/plugins"; let response = await phin<[]>({ url, parse: "json", - core: { ca: control.tlsCa } as {}, + core: { ca: control.tlsCa } as object, }); print(asTable(response.body)); }, @@ -229,7 +229,7 @@ controllerCommands.add(controllerPluginCommands); const hostCommands = new lib.CommandTree({ name: "host", description: "Host management" }); hostCommands.add(new lib.Command({ definition: [["list", "l"], "List hosts connected to the controller"], - handler: async function(args: {}, control: Control) { + handler: async function(args: object, control: Control) { let hosts = await control.send(new lib.HostListRequest()); print(asTable(hosts)); }, @@ -288,7 +288,7 @@ const instanceCommands = new lib.CommandTree({ }); instanceCommands.add(new lib.Command({ definition: [["list", "l"], "List instances known to the controller"], - handler: async function(args: {}, control: Control) { + handler: async function(args: object, control: Control) { let list = await control.send(new lib.InstanceDetailsListRequest()); print(asTable(list)); }, @@ -612,7 +612,7 @@ instanceSaveCommands.add(new lib.Command({ "X-Access-Token": control.config.get("control.controller_token"), "Content-Type": "application/zip", }, - core: { ca: control.tlsCa } as {}, + core: { ca: control.tlsCa } as object, data: content, parse: "json", }); @@ -687,7 +687,7 @@ instanceSaveCommands.add(new lib.Command({ url.pathname += `api/stream/${streamId}`; let response = await phin({ url, method: "GET", - core: { ca: control.tlsCa } as {}, + core: { ca: control.tlsCa } as object, stream: true, }); @@ -898,13 +898,13 @@ modPackCommands.add(new lib.Command({ modPackCommands.add(new lib.Command({ definition: [["list", "l"], "List mod packs in the cluster"], - handler: async function(args: {}, control: Control) { + handler: async function(args: object, control: Control) { let modPacks = await control.send(new lib.ModPackListRequest()); let fields = ["id", "name", "factorioVersion"]; for (let entry of modPacks) { for (let field of Object.keys(entry)) { if (!fields.includes(field)) { - // @ts-ignore + // @ts-expect-error terrible hack delete entry[field]; } } @@ -1176,7 +1176,7 @@ modCommands.add(new lib.Command({ for (let entry of mods) { for (let field of Object.keys(entry)) { if (!args.fields.includes(field)) { - // @ts-ignore + // @ts-expect-error terrible hack delete entry[field]; } } @@ -1243,7 +1243,7 @@ modCommands.add(new lib.Command({ for (let entry of results) { for (let field of Object.keys(entry)) { if (!args.fields.includes(field)) { - // @ts-ignore + // @ts-expect-error terrible hack delete entry[field]; } } @@ -1281,7 +1281,7 @@ modCommands.add(new lib.Command({ "X-Access-Token": control.config.get("control.controller_token"), "Content-Type": "application/zip", }, - core: { ca: control.tlsCa } as {}, + core: { ca: control.tlsCa } as object, data: content, parse: "json", }); @@ -1317,7 +1317,7 @@ modCommands.add(new lib.Command({ url.pathname += `api/stream/${streamId}`; let response = await phin({ url, method: "GET", - core: { ca: control.tlsCa } as {}, + core: { ca: control.tlsCa } as object, stream: true, }); @@ -1358,7 +1358,7 @@ modCommands.add(new lib.Command({ const permissionCommands = new lib.CommandTree({ name: "permission", description: "Permission inspection" }); permissionCommands.add(new lib.Command({ definition: [["list", "l"], "List permissions in the cluster"], - handler: async function(args: {}, control: Control) { + handler: async function(args: object, control: Control) { let permissions = await control.send(new lib.PermissionListRequest()); print(asTable(permissions)); }, @@ -1368,7 +1368,7 @@ permissionCommands.add(new lib.Command({ const roleCommands = new lib.CommandTree({ name: "role", description: "Role management" }); roleCommands.add(new lib.Command({ definition: [["list", "l"], "List roles in the cluster"], - handler: async function(args: {}, control: Control) { + handler: async function(args: object, control: Control) { let roles = await control.send(new lib.RoleListRequest()); print(asTable(roles)); }, @@ -1716,7 +1716,7 @@ logCommands.add(new lib.Command({ const debugCommands = new lib.CommandTree({ name: "debug", description: "Debugging utilities" }); debugCommands.add(new lib.Command({ definition: ["dump-ws", "Dump WebSocket messages sent and received by controller"], - handler: async function(args: {}, control: Control) { + handler: async function(args: object, control: Control) { await control.send(new lib.DebugDumpWsRequest()); control.keepOpen = true; }, diff --git a/packages/host/src/Host.ts b/packages/host/src/Host.ts index 7af872c0..b6311733 100644 --- a/packages/host/src/Host.ts +++ b/packages/host/src/Host.ts @@ -688,7 +688,7 @@ export default class Host extends lib.Link { url.pathname += `api/stream/${streamId}`; let response = await phin({ url, method: "GET", - core: { ca: this.tlsCa } as {}, + core: { ca: this.tlsCa } as object, stream: true, }); @@ -743,7 +743,7 @@ export default class Host extends lib.Link { url.pathname += `api/stream/${streamId}`; phin({ url, method: "PUT", - core: { ca: this.tlsCa } as {}, + core: { ca: this.tlsCa } as object, data: content, }).catch(err => { logger.error(`Error pushing save to controller:\n${err.stack}`, this.instanceLogMeta(instanceId)); diff --git a/packages/host/src/Instance.ts b/packages/host/src/Instance.ts index 0288ee1e..1f3f0800 100644 --- a/packages/host/src/Instance.ts +++ b/packages/host/src/Instance.ts @@ -1067,7 +1067,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); let response = await phin({ url, method: "PUT", data: content, - core: { ca: this._host.tlsCa } as {}, + core: { ca: this._host.tlsCa } as object, headers: { "Content-Type": "application/zip", "x-access-token": this._host.config.get("host.controller_token"), diff --git a/packages/host/src/server.ts b/packages/host/src/server.ts index a2404bb1..628db7f0 100644 --- a/packages/host/src/server.ts +++ b/packages/host/src/server.ts @@ -692,9 +692,9 @@ export class FactorioServer extends events.EventEmitter { this._maxConcurrentCommands = value; this.setMaxListeners(value + 5); if (this._rconClient) { - // @ts-ignore + // @ts-expect-error sendQueue is private if (this._rconClient.sendQueue) { - // @ts-ignore + // @ts-expect-error sendQueue is private this._rconClient.sendQueue.maxConcurrent = value; } // XXX: Workaround to suppress bogus event listener warning diff --git a/packages/lib/src/RateLimiter.ts b/packages/lib/src/RateLimiter.ts index 16271d0f..b96fbc51 100644 --- a/packages/lib/src/RateLimiter.ts +++ b/packages/lib/src/RateLimiter.ts @@ -27,7 +27,7 @@ export default class RateLimiter { /** * Callback invoked at most `maxRate` per second on activation. */ - action?: Function; + action?: () => void; private _lastRun = 0; private _runTimeout?: ReturnType; @@ -43,7 +43,7 @@ export default class RateLimiter { * @param options.action - * Callback invoked at maste `maxRate` per second on activation. */ - constructor(options: { maxRate?: number, action?: Function } = {}) { + constructor(options: { maxRate?: number, action?: () => void } = {}) { this.maxRate = options.maxRate || 1; this.action = options.action || undefined; } diff --git a/packages/lib/src/helpers.ts b/packages/lib/src/helpers.ts index 37c41e51..a3e58571 100644 --- a/packages/lib/src/helpers.ts +++ b/packages/lib/src/helpers.ts @@ -41,7 +41,7 @@ export async function timeout(promise: Promise, time: number, timeoutResul try { return await Promise.race([ promise, - new Promise(resolve => { + new Promise(resolve => { timer = setTimeout(() => resolve(timeoutResult), time); }), ]); diff --git a/packages/lib/src/link/connectors.ts b/packages/lib/src/link/connectors.ts index 2f22236d..b8b6686c 100644 --- a/packages/lib/src/link/connectors.ts +++ b/packages/lib/src/link/connectors.ts @@ -101,10 +101,6 @@ export abstract class WebSocketBaseConnector extends BaseConnector { _lastReceivedSeq = undefined; _sendBuffer: (libData.MessageRoutable)[] = []; - constructor(src: libData.Address, dst: libData.Address) { - super(src, dst); - } - _reset() { this._state = "closed"; this._closing = false; diff --git a/packages/lib/src/logging.ts b/packages/lib/src/logging.ts index 0e6e6e97..c673f98e 100644 --- a/packages/lib/src/logging.ts +++ b/packages/lib/src/logging.ts @@ -44,7 +44,7 @@ export class ConsoleTransport extends Transport { this.filter = options.filter || (() => true); } - log(info: any, callback: Function) { + log(info: any, callback: () => void) { if (!this.filter(info)) { return callback(); } @@ -70,7 +70,7 @@ export class WebConsoleFormat { public options = {} ) { } - transform(info: any, _options: {}) { + transform(info: any, _options: object) { let src = " "; if (info.host_id !== undefined) { src += `s:${info.host_name} - `; @@ -174,5 +174,5 @@ export type Logger = Omit void) { if (this.filter && !this.filter(info)) { return callback(); } diff --git a/packages/lib/src/plugin.ts b/packages/lib/src/plugin.ts index de5c55c7..261a684d 100644 --- a/packages/lib/src/plugin.ts +++ b/packages/lib/src/plugin.ts @@ -4,15 +4,12 @@ */ import * as libHelpers from "./helpers"; import type { Logger } from "./logging"; -import type { ConfigGroup } from "./config"; +import type { ConfigGroup, PluginConfigGroup } from "./config"; import type { CollectorResult } from "./prometheus"; import type { ParsedFactorioOutput } from "./logging_utils"; import type { ModPack, ModInfo } from "./data"; import type { Link } from "./link"; import type { CommandTree } from "./command"; -import type { User } from "./users"; -import type { MessageRequest, MessageEvent } from "./data"; -import type { PluginConfigGroup } from "./config"; /** * Conceptual base for controller and instance plugins. @@ -365,7 +362,7 @@ export class BaseControllerPlugin { constructor( public info: PluginNodeEnvInfo, public controller: Controller, - public metrics: any[], + public metrics: any, logger: Logger ) { this.logger = logger.child({ plugin: this.info.name }) as unknown as Logger; diff --git a/packages/web_ui/src/components/HostsPage.tsx b/packages/web_ui/src/components/HostsPage.tsx index 4816301b..8b70a713 100644 --- a/packages/web_ui/src/components/HostsPage.tsx +++ b/packages/web_ui/src/components/HostsPage.tsx @@ -61,8 +61,7 @@ function GenerateHostTokenButton() { }, [open]); // Only install plugins that aren't filesystem paths. Npm modules have max 1 forward slash in their name. - //@ts-ignore TODO::: this doesn't filter anything, `x.split("/") <= 1` is always = true. repair or shouldn't filter ? - const pluginString = pluginList.map(p => `"${p.requirePath}"`).filter(x => x.split("/") <= 1).join(" "); + const pluginString = pluginList.map(p => `"${p.requirePath}"`).filter(x => x.split("/").length <= 1).join(" "); return <>