Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/okikio/codemirror. A minor test of Codemirror okikio-codemirror.netlify.app
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// Based off of https://www.npmjs.com/package/@open-rpc/client-jsexport type JSONRPCRequestData = IJSONRPCData | IBatchRequest[] ;
export interface IJSONRPCData { internalID: string | number; request: IJSONRPCRequest | IJSONRPCNotification;}
export interface IBatchRequest { resolve: (data: any) => void; reject: (data: any) => void; request: IJSONRPCData; // IJSONRPCNotification | IJSONRPCRequest; }
export interface IJSONRPCRequest { jsonrpc: "2.0"; id: string | number; method: string; params: any[] | object;}
export interface IJSONRPCError { code: number; message: string; data: any;}
export interface IJSONRPCResponse { jsonrpc: "2.0"; id?: string | number; // can also be null result?: any; error?: IJSONRPCError;}
export interface IJSONRPCNotificationResponse { jsonrpc: "2.0"; id?: null | undefined; result?: any; error?: IJSONRPCError;}
export interface IJSONRPCNotification { jsonrpc: "2.0"; id?: null | undefined; method: string; params: any[] | object;}
interface IRPCRequest { method: string; params: any[]; type: "single";}
interface IBatchRPCRequest { type: "batch"; batch: IJSONRPCRequest[];}
export type Request = IRPCRequest | IBatchRPCRequest;
export const isNotification = (data: IJSONRPCData): boolean => { return (data.request.id === undefined || data.request.id === null);};
export const getBatchRequests = (data: JSONRPCRequestData): IJSONRPCData[] => { if (data instanceof Array) { return data.filter((datum) => { const id = datum.request.request.id; return id !== null && id !== undefined; }).map((batchRequest: IBatchRequest) => { return batchRequest.request; }); } return [];};export const getNotifications = (data: JSONRPCRequestData): IJSONRPCData[] => { if (data instanceof Array) { return data.filter((datum) => { return isNotification(datum.request); }).map((batchRequest: IBatchRequest) => { return batchRequest.request; }); } if (isNotification(data)) { return [data]; } return [];};