53 lines
991 B
TypeScript
53 lines
991 B
TypeScript
export const Logging = {
|
|
verbose: false,
|
|
log(...args: any[]) {
|
|
if (Logging.verbose) {
|
|
console.log(...args);
|
|
}
|
|
},
|
|
};
|
|
|
|
export enum ErrorCodes {
|
|
ParseError = -32700,
|
|
InvalidRequest = -32700,
|
|
MethodNotFound = -32700,
|
|
InvalidParams = -32700,
|
|
InternalError = -32700,
|
|
}
|
|
|
|
export interface RequestObject {
|
|
jsonrpc: "2.0";
|
|
method: string;
|
|
params?: any[] | { [key: string]: any };
|
|
id?: string | null;
|
|
}
|
|
|
|
export interface ResponseObject {
|
|
jsonrpc: "2.0";
|
|
result?: 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;
|
|
}
|
|
|
|
export function verify_void(data: any) {
|
|
return true;
|
|
}
|