mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 00:23:12 +09:00
Fix bad typings in lib
These were missed or broken in the in the inital porting of lib to TypeScript.
This commit is contained in:
1 parent
6d523096ce
commit
5ec7c9f99c
7 files changed
+25
-39
No files matched your search
@@ -37,8 +37,10 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/fs-extra": "^11.0.1",
|
"@types/fs-extra": "^11.0.1",
|
||||||
"@types/node": "^20.4.5",
|
"@types/node": "^20.4.5",
|
||||||
|
"@types/set-blocking": "^2.0.0",
|
||||||
"@types/triple-beam": "^1.3.2",
|
"@types/triple-beam": "^1.3.2",
|
||||||
"@types/ws": "^8.5.5",
|
"@types/ws": "^8.5.5",
|
||||||
|
"@types/yargs": "^17.0.24",
|
||||||
"typescript": "^5.1.6"
|
"typescript": "^5.1.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,10 +9,10 @@
|
|||||||
import * as libData from "./data";
|
import * as libData from "./data";
|
||||||
import * as libErrors from "./errors";
|
import * as libErrors from "./errors";
|
||||||
import type { Link } from "./link";
|
import type { Link } from "./link";
|
||||||
|
import type { Argv } from "yargs";
|
||||||
|
|
||||||
|
export type CommandHandler = (args: any, control: any) => Promise<void>;
|
||||||
export type CommandHandler = (args: Record<string, unknown>, control: Link) => Promise<void>;
|
export type CommandDefinition = [string | string[], string?, ((yargs: Argv) => void)?];
|
||||||
export type CommandDefinition = [string | string[], string?, Function?];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a command that can be runned by clusterioctl
|
* Represents a command that can be runned by clusterioctl
|
||||||
@@ -80,7 +80,7 @@ export class CommandTree {
|
|||||||
* @param cmd.description -
|
* @param cmd.description -
|
||||||
* Descripton to provide for this command tree node.
|
* Descripton to provide for this command tree node.
|
||||||
*/
|
*/
|
||||||
constructor({ name, alias, description }: { name: string, alias: string[], description: string }) {
|
constructor({ name, alias, description }: { name: string, alias?: string[], description: string }) {
|
||||||
if (typeof name !== "string") {
|
if (typeof name !== "string") {
|
||||||
throw new Error("name must be a string");
|
throw new Error("name must be a string");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import type { PluginInfo } from "../plugin";
|
|||||||
* Controller config group for {@link ControllerConfig}
|
* Controller config group for {@link ControllerConfig}
|
||||||
* @extends classes.ConfigGroup
|
* @extends classes.ConfigGroup
|
||||||
*/
|
*/
|
||||||
class ControllerGroup extends classes.ConfigGroup { }
|
export class ControllerGroup extends classes.ConfigGroup { }
|
||||||
ControllerGroup.defaultAccess = ["controller", "host", "control"];
|
ControllerGroup.defaultAccess = ["controller", "host", "control"];
|
||||||
ControllerGroup.groupName = "controller";
|
ControllerGroup.groupName = "controller";
|
||||||
ControllerGroup.define({
|
ControllerGroup.define({
|
||||||
@@ -140,7 +140,7 @@ ControllerGroup.finalize();
|
|||||||
* Controller Config class
|
* Controller Config class
|
||||||
* @extends classes.Config
|
* @extends classes.Config
|
||||||
*/
|
*/
|
||||||
class ControllerConfig extends classes.Config { }
|
export class ControllerConfig extends classes.Config { }
|
||||||
ControllerConfig.registerGroup(ControllerGroup);
|
ControllerConfig.registerGroup(ControllerGroup);
|
||||||
|
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ ControllerConfig.registerGroup(ControllerGroup);
|
|||||||
* Host config group for {@link HostConfig}
|
* Host config group for {@link HostConfig}
|
||||||
* @extends classes.ConfigGroup
|
* @extends classes.ConfigGroup
|
||||||
*/
|
*/
|
||||||
class HostGroup extends classes.ConfigGroup {}
|
export class HostGroup extends classes.ConfigGroup {}
|
||||||
HostGroup.defaultAccess = ["controller", "host", "control"];
|
HostGroup.defaultAccess = ["controller", "host", "control"];
|
||||||
HostGroup.groupName = "host";
|
HostGroup.groupName = "host";
|
||||||
HostGroup.define({
|
HostGroup.define({
|
||||||
@@ -230,7 +230,7 @@ HostGroup.finalize();
|
|||||||
* Host Config class
|
* Host Config class
|
||||||
* @extends classes.Config
|
* @extends classes.Config
|
||||||
*/
|
*/
|
||||||
class HostConfig extends classes.Config { }
|
export class HostConfig extends classes.Config { }
|
||||||
HostConfig.registerGroup(HostGroup);
|
HostConfig.registerGroup(HostGroup);
|
||||||
|
|
||||||
|
|
||||||
@@ -238,7 +238,7 @@ HostConfig.registerGroup(HostGroup);
|
|||||||
* Instance config group for {@link classes.InstanceConfig}
|
* Instance config group for {@link classes.InstanceConfig}
|
||||||
* @extends classes.ConfigGroup
|
* @extends classes.ConfigGroup
|
||||||
*/
|
*/
|
||||||
class InstanceGroup extends classes.ConfigGroup { }
|
export class InstanceGroup extends classes.ConfigGroup { }
|
||||||
InstanceGroup.defaultAccess = ["controller", "host", "control"];
|
InstanceGroup.defaultAccess = ["controller", "host", "control"];
|
||||||
InstanceGroup.groupName = "instance";
|
InstanceGroup.groupName = "instance";
|
||||||
InstanceGroup.define({
|
InstanceGroup.define({
|
||||||
@@ -269,7 +269,7 @@ InstanceGroup.finalize();
|
|||||||
* Factorio config group for {@link classes.InstanceConfig}
|
* Factorio config group for {@link classes.InstanceConfig}
|
||||||
* @extends classes.ConfigGroup
|
* @extends classes.ConfigGroup
|
||||||
*/
|
*/
|
||||||
class FactorioGroup extends classes.ConfigGroup { }
|
export class FactorioGroup extends classes.ConfigGroup { }
|
||||||
FactorioGroup.defaultAccess = ["controller", "host", "control"];
|
FactorioGroup.defaultAccess = ["controller", "host", "control"];
|
||||||
FactorioGroup.groupName = "factorio";
|
FactorioGroup.groupName = "factorio";
|
||||||
FactorioGroup.define({
|
FactorioGroup.define({
|
||||||
@@ -393,7 +393,7 @@ FactorioGroup.finalize();
|
|||||||
* Instance config class
|
* Instance config class
|
||||||
* @extends classes.Config
|
* @extends classes.Config
|
||||||
*/
|
*/
|
||||||
class InstanceConfig extends classes.Config { }
|
export class InstanceConfig extends classes.Config { }
|
||||||
InstanceConfig.registerGroup(InstanceGroup);
|
InstanceConfig.registerGroup(InstanceGroup);
|
||||||
InstanceConfig.registerGroup(FactorioGroup);
|
InstanceConfig.registerGroup(FactorioGroup);
|
||||||
|
|
||||||
@@ -402,7 +402,7 @@ InstanceConfig.registerGroup(FactorioGroup);
|
|||||||
* Control config group for {@link classes.ControlConfig}
|
* Control config group for {@link classes.ControlConfig}
|
||||||
* @extends classes.ConfigGroup
|
* @extends classes.ConfigGroup
|
||||||
*/
|
*/
|
||||||
class ControlGroup extends classes.ConfigGroup {}
|
export class ControlGroup extends classes.ConfigGroup {}
|
||||||
ControlGroup.defaultAccess = ["control"];
|
ControlGroup.defaultAccess = ["control"];
|
||||||
ControlGroup.groupName = "control";
|
ControlGroup.groupName = "control";
|
||||||
ControlGroup.define({
|
ControlGroup.define({
|
||||||
@@ -436,7 +436,7 @@ ControlGroup.finalize();
|
|||||||
* Control config class
|
* Control config class
|
||||||
* @extends classes.Config
|
* @extends classes.Config
|
||||||
*/
|
*/
|
||||||
class ControlConfig extends classes.Config { }
|
export class ControlConfig extends classes.Config { }
|
||||||
ControlConfig.registerGroup(ControlGroup);
|
ControlConfig.registerGroup(ControlGroup);
|
||||||
|
|
||||||
|
|
||||||
@@ -459,7 +459,7 @@ function validateGroup(pluginInfo: PluginInfo, groupName: string) {
|
|||||||
*
|
*
|
||||||
* @param {Array<Object>} pluginInfos - Array of plugin info objects.
|
* @param {Array<Object>} pluginInfos - Array of plugin info objects.
|
||||||
*/
|
*/
|
||||||
function registerPluginConfigGroups(pluginInfos: PluginInfo[]) {
|
export function registerPluginConfigGroups(pluginInfos: PluginInfo[]) {
|
||||||
for (let pluginInfo of pluginInfos) {
|
for (let pluginInfo of pluginInfos) {
|
||||||
if (pluginInfo.ControllerConfigGroup) {
|
if (pluginInfo.ControllerConfigGroup) {
|
||||||
validateGroup(pluginInfo, "ControllerConfigGroup");
|
validateGroup(pluginInfo, "ControllerConfigGroup");
|
||||||
@@ -492,25 +492,9 @@ function registerPluginConfigGroups(pluginInfos: PluginInfo[]) {
|
|||||||
/**
|
/**
|
||||||
* Lock configs from adding more groups and make them usable
|
* Lock configs from adding more groups and make them usable
|
||||||
*/
|
*/
|
||||||
function finalizeConfigs() {
|
export function finalizeConfigs() {
|
||||||
ControllerConfig.finalize();
|
ControllerConfig.finalize();
|
||||||
HostConfig.finalize();
|
HostConfig.finalize();
|
||||||
InstanceConfig.finalize();
|
InstanceConfig.finalize();
|
||||||
ControlConfig.finalize();
|
ControlConfig.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
ControllerGroup,
|
|
||||||
HostGroup,
|
|
||||||
InstanceGroup,
|
|
||||||
FactorioGroup,
|
|
||||||
ControlGroup,
|
|
||||||
|
|
||||||
ControllerConfig,
|
|
||||||
HostConfig,
|
|
||||||
InstanceConfig,
|
|
||||||
ControlConfig,
|
|
||||||
|
|
||||||
registerPluginConfigGroups,
|
|
||||||
finalizeConfigs,
|
|
||||||
};
|
|
||||||
@@ -193,7 +193,7 @@ export class ModSearchRequest {
|
|||||||
public queryIssues: string[],
|
public queryIssues: string[],
|
||||||
public pageCount: number,
|
public pageCount: number,
|
||||||
public resultCount: number,
|
public resultCount: number,
|
||||||
public results: object[],
|
public results: { name: string, versions: ModInfo[] }[],
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ export abstract class WebSocketClientConnector extends WebSocketBaseConnector {
|
|||||||
constructor(
|
constructor(
|
||||||
protected _url: string,
|
protected _url: string,
|
||||||
maxReconnectDelay: number,
|
maxReconnectDelay: number,
|
||||||
protected _tlsCa = null
|
protected _tlsCa: string | undefined,
|
||||||
) {
|
) {
|
||||||
super(undefined as any, new libData.Address(libData.Address.controller, 0));
|
super(undefined as any, new libData.Address(libData.Address.controller, 0));
|
||||||
this._backoff = new ExponentialBackoff({ max: maxReconnectDelay });
|
this._backoff = new ExponentialBackoff({ max: maxReconnectDelay });
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ interface EventEntry {
|
|||||||
allowedDstTypes: Set<number>;
|
allowedDstTypes: Set<number>;
|
||||||
eventFromJSON: (json: any) => Event<unknown>;
|
eventFromJSON: (json: any) => Event<unknown>;
|
||||||
}
|
}
|
||||||
type RequestHandler<Req, Res> = (request: Request<Req, Res>, src: libData.Address, dst: libData.Address) => any;
|
type RequestHandler<Req, Res> = (request: Req, src: libData.Address, dst: libData.Address) => Promise<Res>;
|
||||||
type EventHandler<T> = (event: Event<T>, src: libData.Address, dst: libData.Address) => any;
|
type EventHandler<T> = (event: T, src: libData.Address, dst: libData.Address) => Promise<void>;
|
||||||
|
|
||||||
interface Router {
|
interface Router {
|
||||||
forwardMessage(origin: Link, message: Message, fallback: boolean): boolean,
|
forwardMessage(origin: Link, message: Message, fallback: boolean): boolean,
|
||||||
@@ -99,7 +99,7 @@ export class Link {
|
|||||||
constructor(
|
constructor(
|
||||||
public connector: BaseConnector
|
public connector: BaseConnector
|
||||||
) {
|
) {
|
||||||
this.handle(libData.PingRequest, () => {});
|
this.handle(libData.PingRequest, async () => {});
|
||||||
|
|
||||||
// Process messages received by the connector
|
// Process messages received by the connector
|
||||||
connector.on("message", payload => {
|
connector.on("message", payload => {
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ function loadPluginClass(
|
|||||||
*/
|
*/
|
||||||
export async function loadControllerPluginClass(
|
export async function loadControllerPluginClass(
|
||||||
pluginInfo: libPlugin.PluginInfo
|
pluginInfo: libPlugin.PluginInfo
|
||||||
): Promise<libPlugin.BaseControllerPlugin> {
|
): Promise<typeof libPlugin.BaseControllerPlugin> {
|
||||||
return loadPluginClass("controllerEntrypoint", "ControllerPlugin", libPlugin.BaseControllerPlugin, pluginInfo);
|
return loadPluginClass("controllerEntrypoint", "ControllerPlugin", libPlugin.BaseControllerPlugin, pluginInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ export async function loadControllerPluginClass(
|
|||||||
*/
|
*/
|
||||||
export async function loadInstancePluginClass(
|
export async function loadInstancePluginClass(
|
||||||
pluginInfo: libPlugin.PluginInfo
|
pluginInfo: libPlugin.PluginInfo
|
||||||
): Promise<libPlugin.BaseInstancePlugin> {
|
): Promise<typeof libPlugin.BaseInstancePlugin> {
|
||||||
return loadPluginClass("instanceEntrypoint", "InstancePlugin", libPlugin.BaseInstancePlugin, pluginInfo);
|
return loadPluginClass("instanceEntrypoint", "InstancePlugin", libPlugin.BaseInstancePlugin, pluginInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +112,6 @@ export async function loadInstancePluginClass(
|
|||||||
*/
|
*/
|
||||||
export async function loadControlPluginClass(
|
export async function loadControlPluginClass(
|
||||||
pluginInfo: libPlugin.PluginInfo
|
pluginInfo: libPlugin.PluginInfo
|
||||||
): Promise<libPlugin.BaseControlPlugin> {
|
): Promise<typeof libPlugin.BaseControlPlugin> {
|
||||||
return loadPluginClass("controlEntrypoint", "ControlPlugin", libPlugin.BaseControlPlugin, pluginInfo);
|
return loadPluginClass("controlEntrypoint", "ControlPlugin", libPlugin.BaseControlPlugin, pluginInfo);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user