UNPKG

ws-rmi

Version:

A Remote Method Invocation implementation written in JavaScript utilising the WebSocket protocol

32 lines (31 loc) 1.35 kB
import { Validator } from "../JSONValidation"; import { RMIMessageType } from "./RMIMessageType"; /** * Represents a message that is sent from client to server and vice-versa. This is the base type, and should * be used by sub-types to represent a full message. */ export declare type RMIMessage<T extends RMIMessageType, D> = { rmi: { version: "1"; id: string; type: T; data: D; }; }; /** * Creates an object that matches the {@link RMIMessage} schema. This is generally used by sub-types to * create full message objects. * * @param id The ID of the message to be created. * @param type The type of message to be created. * @param data The data to be inserted into this message. */ export declare const createRMIMessage: <T extends RMIMessageType, D>(id: string, type: T, data: D) => RMIMessage<T, D>; /** * Returns a function that can be used to validate a message that should be validated as an RMI message. Assuming * the message conforms to the schema of an RMI message, the given dataValidator will be used to validate the inner * `data` property. * * @param dataValidator A function to validate the `data` property of the message. */ export declare const createRMIMessageValidator: <D>(dataValidator: Validator<D>) => (message: unknown) => message is RMIMessage<RMIMessageType, D>;