From ceb4a05289e11b79e8db8ba733d9d13b43f409e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB=20Hoekstra?= Date: Thu, 25 Aug 2022 23:34:29 +0200 Subject: [PATCH 1/2] Fix type of RFAMessages with non-String results --- src/RemoteFileAPI/MessageDefinitions.ts | 4 ++-- src/RemoteFileAPI/MessageHandlers.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RemoteFileAPI/MessageDefinitions.ts b/src/RemoteFileAPI/MessageDefinitions.ts index 05b21ad02..75386f72a 100644 --- a/src/RemoteFileAPI/MessageDefinitions.ts +++ b/src/RemoteFileAPI/MessageDefinitions.ts @@ -1,13 +1,13 @@ export class RFAMessage { jsonrpc = "2.0"; // Transmits version of JSON-RPC. Compliance maybe allows some funky interaction with external tools? public method?: string; // Is defined when it's a request/notification, otherwise undefined - public result?: string | number; // Is defined when it's a response, otherwise undefined + public result?: string | Array | number; // Is defined when it's a response, otherwise undefined public params?: FileMetadata; // Optional parameters to method public error?: string; // Only defined on error public id?: number; // ID to keep track of request -> response interaction, undefined with notifications, defined with request/response constructor( - obj: { method?: string; result?: string | number; params?: FileMetadata; error?: string; id?: number } = {}, + obj: { method?: string; result?: string | Array | number; params?: FileMetadata; error?: string; id?: number } = {}, ) { this.method = obj.method; this.result = obj.result; diff --git a/src/RemoteFileAPI/MessageHandlers.ts b/src/RemoteFileAPI/MessageHandlers.ts index 068f7b1cb..0c9326ed2 100644 --- a/src/RemoteFileAPI/MessageHandlers.ts +++ b/src/RemoteFileAPI/MessageHandlers.ts @@ -93,7 +93,7 @@ export const RFARequestHandler: Record void | R ...server.scripts.map((scr): string => scr.filename), ]; - return new RFAMessage({ result: JSON.stringify(fileNameList), id: msg.id }); + return new RFAMessage({ result: fileNameList, id: msg.id }); }, getAllFiles: function (msg: RFAMessage): RFAMessage { @@ -111,7 +111,7 @@ export const RFARequestHandler: Record void | R }), ]; - return new RFAMessage({ result: JSON.stringify(fileList), id: msg.id }); + return new RFAMessage({ result: fileList, id: msg.id }); }, calculateRam: function (msg: RFAMessage): RFAMessage { From 45c15c9953a46a3f4c99e009f7368c8303d95c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB=20Hoekstra?= Date: Fri, 26 Aug 2022 11:31:37 +0200 Subject: [PATCH 2/2] Extract result type and correct it for getAllFiles --- src/RemoteFileAPI/MessageDefinitions.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/RemoteFileAPI/MessageDefinitions.ts b/src/RemoteFileAPI/MessageDefinitions.ts index 75386f72a..6ca272749 100644 --- a/src/RemoteFileAPI/MessageDefinitions.ts +++ b/src/RemoteFileAPI/MessageDefinitions.ts @@ -1,14 +1,12 @@ export class RFAMessage { jsonrpc = "2.0"; // Transmits version of JSON-RPC. Compliance maybe allows some funky interaction with external tools? public method?: string; // Is defined when it's a request/notification, otherwise undefined - public result?: string | Array | number; // Is defined when it's a response, otherwise undefined + public result?: ResultType; // Is defined when it's a response, otherwise undefined public params?: FileMetadata; // Optional parameters to method public error?: string; // Only defined on error public id?: number; // ID to keep track of request -> response interaction, undefined with notifications, defined with request/response - constructor( - obj: { method?: string; result?: string | Array | number; params?: FileMetadata; error?: string; id?: number } = {}, - ) { + constructor(obj: { method?: string; result?: ResultType; params?: FileMetadata; error?: string; id?: number } = {}) { this.method = obj.method; this.result = obj.result; this.params = obj.params; @@ -17,6 +15,7 @@ export class RFAMessage { } } +type ResultType = string | number | Array | Array; type FileMetadata = FileData | FileContent | FileLocation | FileServer; export interface FileData {