2022-07-30 16:19:22 +02:00
|
|
|
export class RFAMessage {
|
2022-08-10 23:22:03 +02:00
|
|
|
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
|
2022-08-26 11:31:37 +02:00
|
|
|
public result?: ResultType; // Is defined when it's a response, otherwise undefined
|
2022-08-10 23:22:03 +02:00
|
|
|
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
|
2022-07-30 16:19:22 +02:00
|
|
|
|
2022-08-26 11:31:37 +02:00
|
|
|
constructor(obj: { method?: string; result?: ResultType; params?: FileMetadata; error?: string; id?: number } = {}) {
|
2022-08-10 23:22:03 +02:00
|
|
|
this.method = obj.method;
|
|
|
|
this.result = obj.result;
|
|
|
|
this.params = obj.params;
|
|
|
|
this.error = obj.error;
|
|
|
|
this.id = obj.id;
|
|
|
|
}
|
2022-07-30 16:19:22 +02:00
|
|
|
}
|
|
|
|
|
2022-08-26 11:31:37 +02:00
|
|
|
type ResultType = string | number | Array<string> | Array<FileContent>;
|
2022-08-10 23:22:03 +02:00
|
|
|
type FileMetadata = FileData | FileContent | FileLocation | FileServer;
|
2022-07-30 16:19:22 +02:00
|
|
|
|
|
|
|
export interface FileData {
|
2022-08-10 23:22:03 +02:00
|
|
|
filename: string;
|
|
|
|
content: string;
|
|
|
|
server: string;
|
2022-07-30 16:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface FileContent {
|
2022-08-10 23:22:03 +02:00
|
|
|
filename: string;
|
|
|
|
content: string;
|
2022-07-30 16:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface FileLocation {
|
2022-08-10 23:22:03 +02:00
|
|
|
filename: string;
|
|
|
|
server: string;
|
2022-07-30 16:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface FileServer {
|
2022-08-10 23:22:03 +02:00
|
|
|
server: string;
|
2022-07-30 16:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function isFileData(p: unknown): p is FileData {
|
2022-08-10 23:22:03 +02:00
|
|
|
const pf = p as FileData;
|
|
|
|
return typeof pf.server === "string" && typeof pf.filename === "string" && typeof pf.content === "string";
|
2022-07-30 16:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function isFileLocation(p: unknown): p is FileLocation {
|
2022-08-10 23:22:03 +02:00
|
|
|
const pf = p as FileLocation;
|
|
|
|
return typeof pf.server === "string" && typeof pf.filename === "string";
|
2022-07-30 16:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function isFileContent(p: unknown): p is FileContent {
|
2022-08-10 23:22:03 +02:00
|
|
|
const pf = p as FileContent;
|
|
|
|
return typeof pf.filename === "string" && typeof pf.content === "string";
|
2022-07-30 16:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function isFileServer(p: unknown): p is FileServer {
|
2022-08-10 23:22:03 +02:00
|
|
|
const pf = p as FileServer;
|
|
|
|
return typeof pf.server === "string";
|
2022-07-30 16:19:22 +02:00
|
|
|
}
|