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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
export 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 [];};