Adding parameter and response validation.

Adding prettier formatting support.
Add warning when no targets are selected.
This commit is contained in:
K35
2022-01-01 00:39:15 +00:00
parent cc6035eef0
commit 7da1cf0841
7 changed files with 248 additions and 132 deletions

View File

@ -1,18 +1,18 @@
export const Logging = {
export const Logging = {
verbose: false,
log(...args: any[]) {
if(Logging.verbose) {
console.log(...args)
if (Logging.verbose) {
console.log(...args);
}
}
}
},
};
export enum ErrorCodes {
ParseError=-32700,
InvalidRequest=-32700,
MethodNotFound=-32700,
InvalidParams=-32700,
InternalError=-32700,
ParseError = -32700,
InvalidRequest = -32700,
MethodNotFound = -32700,
InvalidParams = -32700,
InternalError = -32700,
}
export interface RequestObject {
@ -25,6 +25,24 @@ export interface RequestObject {
export interface ResponseObject {
jsonrpc: "2.0";
result?: any;
error?: { code: ErrorCodes, message:string, data?: any}
error?: { code: ErrorCodes; message: string; data?: any };
id: string;
}
export function verify_number(data: any) {
if (typeof data !== "number") return false;
return true;
}
export function verify_string(data: any) {
if (typeof data !== "string") return false;
return true;
}
export function verify_boolean(data: any) {
if (typeof data !== "boolean") return false;
return true;
}

View File

@ -34,7 +34,13 @@ export class ServiceProvider {
} else {
Logging.log("CLIENT: Determined type is Notification");
//Notification. Send to Notification handler
//TODO: Implement
const [srvName, fncName] = msg.method.split(".");
let service = this.services.get(srvName)
if(!service) {
Logging.log("CLIENT: Did not find Service wanted by Notification!", srvName);
} else {
//TODO: Implement Event thingy (or so :))
}
}
} else {
Logging.log("CLIENT: Determined type is Response");