From e011625a2d801fae2ac5187df42e16ea65dc8ecf Mon Sep 17 00:00:00 2001 From: Luciole <31817566+Luciole0x@users.noreply.github.com> Date: Sun, 13 Aug 2023 16:53:03 +0200 Subject: [PATCH] expose and/or modify signatures from lib package --- packages/lib/src/config/definitions.ts | 65 +++++++++++++++++++- packages/lib/src/data/messages_controller.ts | 4 +- packages/lib/src/data/messages_core.ts | 4 +- packages/lib/src/link/link.ts | 8 +-- packages/lib/src/logging_utils.ts | 2 +- 5 files changed, 72 insertions(+), 11 deletions(-) diff --git a/packages/lib/src/config/definitions.ts b/packages/lib/src/config/definitions.ts index 13e18599..7d475ae3 100644 --- a/packages/lib/src/config/definitions.ts +++ b/packages/lib/src/config/definitions.ts @@ -140,7 +140,27 @@ ControllerGroup.finalize(); * Controller Config class * @extends classes.Config */ -export class ControllerConfig extends classes.Config { } +export class ControllerConfig extends classes.Config { + get(name: "controller.name"): string; + get(name: "controller.mods_directory"): string; + get(name: "controller.database_directory"): string; + get(name: "controller.http_port"): number | null; + get(name: "controller.https_port"): number | null; + get(name: "controller.bind_address"): string | null; + get(name: "controller.external_address"): string | null; + get(name: "controller.tls_certificate"): string | null; + get(name: "controller.tls_private_key"): string | null; + get(name: "controller.auth_secret"): string | null; + get(name: "controller.heartbeat_interval"): number; + get(name: "controller.session_timeout"): number; + get(name: "controller.metrics_timeout"): number; + get(name: "controller.proxy_stream_timeout"): number; + get(name: "controller.default_mod_pack_id"): number | null; + get(name: "controller.default_role_id"): number | null; + get(name: string) { + return super.get(name); + } +} ControllerConfig.registerGroup(ControllerGroup); @@ -230,7 +250,22 @@ HostGroup.finalize(); * Host Config class * @extends classes.Config */ -export class HostConfig extends classes.Config { } +export class HostConfig extends classes.Config { + get(name: "host.name"): string; + get(name: "host.id"): number; + get(name: "host.factorio_directory"): string; + get(name: "host.mods_directory"): string; + get(name: "host.mods_directory_is_shared"): boolean; + get(name: "host.instances_directory"): string; + get(name: "host.controller_url"): string; + get(name: "host.controller_token"): string; + get(name: "host.tls_ca"): string | null; + get(name: "host.public_address"): string; + get(name: "host.max_reconnect_delay"): number; + get(name: string) { + return super.get(name); + } +} HostConfig.registerGroup(HostGroup); @@ -393,7 +428,31 @@ FactorioGroup.finalize(); * Instance config class * @extends classes.Config */ -export class InstanceConfig extends classes.Config { } +export class InstanceConfig extends classes.Config { + get(name: "instance.name"): string; + get(name: "instance.id"): number; + get(name: "instance.assigned_host"): number | null; + get(name: "instance.auto_start"): boolean; + + get(name: "factorio.version"): string; + get(name: "factorio.game_port"): number | null; + get(name: "factorio.rcon_port"): number | null; + get(name: "factorio.rcon_password"): string | null; + get(name: "factorio.player_online_autosave_slots"): number; + get(name: "factorio.mod_pack"): string | null; + get(name: "factorio.enable_save_patching"): boolean; + get(name: "factorio.enable_whitelist"): boolean; + get(name: "factorio.enable_authserver_bans"): boolean; + get(name: "factorio.settings"): Object; + get(name: "factorio.verbose_logging"): boolean; + get(name: "factorio.strip_paths"): boolean; + get(name: "factorio.sync_adminlist"): boolean; + get(name: "factorio.sync_whitelist"): boolean; + get(name: "factorio.max_concurrent_commands"): number; + get(name: string) { + return super.get(name); + } +} InstanceConfig.registerGroup(InstanceGroup); InstanceConfig.registerGroup(FactorioGroup); diff --git a/packages/lib/src/data/messages_controller.ts b/packages/lib/src/data/messages_controller.ts index ba885145..6534fad3 100644 --- a/packages/lib/src/data/messages_controller.ts +++ b/packages/lib/src/data/messages_controller.ts @@ -80,7 +80,7 @@ export class HostGenerateTokenRequest { static permission = "core.host.generate_token" as const; constructor( - public hostId?: number, + public hostId: number | null = null, ) { } static jsonSchema = Type.Object({ @@ -202,7 +202,7 @@ export class LogMessageEvent { static dst = ["controller", "control"] as const; constructor( - public info: object, + public info: { level: string, message: string }, ) { } static jsonSchema = Type.Object({ diff --git a/packages/lib/src/data/messages_core.ts b/packages/lib/src/data/messages_core.ts index 207fc01a..e27c2bd1 100644 --- a/packages/lib/src/data/messages_core.ts +++ b/packages/lib/src/data/messages_core.ts @@ -48,7 +48,7 @@ export class Address { * Shorthand to translate with. * @returns Translated address. */ - static fromShorthand(shorthand: AddressShorthand) { + static fromShorthand(shorthand: AddressShorthand | Address) { if (shorthand instanceof Address) { return shorthand; } if (shorthand === "controller") { return new Address(Address.controller, 0); } if (shorthand === "allHosts") { return new Address(Address.broadcast, Address.host); } @@ -172,6 +172,8 @@ export class Message { } } +export type MessageSrcDst = MessageRequest | MessageResponse | MessageResponseError | MessageEvent; + export class HelloData { constructor( public version: string, diff --git a/packages/lib/src/link/link.ts b/packages/lib/src/link/link.ts index 2736e79c..99c55037 100644 --- a/packages/lib/src/link/link.ts +++ b/packages/lib/src/link/link.ts @@ -37,7 +37,7 @@ export interface Event { } export type EventClass = Event["constructor"]; -interface RequestEntry { +export interface RequestEntry { Request: RequestClass; name: string, allowedSrcTypes: Set; @@ -60,15 +60,15 @@ interface ForwardedRequest { dst: libData.Address; } -interface EventEntry { +export interface EventEntry { Event: EventClass; name: string, allowedSrcTypes: Set; allowedDstTypes: Set; eventFromJSON: (json: any) => Event; } -type RequestHandler = (request: Req, src: libData.Address, dst: libData.Address) => Promise; -type EventHandler = (event: T, src: libData.Address, dst: libData.Address) => Promise; +export type RequestHandler = (request: Req, src: libData.Address, dst: libData.Address) => Promise; +export type EventHandler = (event: T, src: libData.Address, dst: libData.Address) => Promise; interface Router { forwardMessage(origin: Link, message: Message, fallback: boolean): boolean, diff --git a/packages/lib/src/logging_utils.ts b/packages/lib/src/logging_utils.ts index f55b0ddd..e3cc6c6c 100644 --- a/packages/lib/src/logging_utils.ts +++ b/packages/lib/src/logging_utils.ts @@ -451,7 +451,7 @@ export interface QueryLogFilter { * Index to speed up query with. * @returns log entries matching the filter */ -export async function queryLog(logDirectory: string, filter: QueryLogFilter, index: LogIndex) { +export async function queryLog(logDirectory: string, filter: QueryLogFilter, index: LogIndex | null) { let files = (await fs.readdir(logDirectory)).filter(entry => logFileGlob.test(entry)); filter = {