/** * MHub Message class. */ /** * Headers are key-value pairs that carry meta-information * about a message. */ export interface Headers { [name: string]: string | boolean | number; } /** * Interface describing what a 'raw' object should look like * if it is to be converted to a Message using `Message.fromObject()`. */ export interface MessageLike { topic: string; data?: any; headers?: Headers; } /** * Message to be sent or received over MHub network. */ export declare class Message { /** * Create a Message object from a plain object, by taking its topic, data and * headers properties. * * Note that the data is not deep-cloned. * * @param o Input object. Must at least contain a `.topic` property. * @return New `Message` instance, with given topic, same data, and clone of headers. */ static fromObject(o: MessageLike): Message; /** * Topic of message. * Can be used to determine routing between pubsub Nodes. */ topic: string; /** * Optional message data, can be null. * Must be JSON serializable. */ data: any; /** * Optional message headers. */ headers: Headers; /** * Construct message object. * * Note: headers are cloned, but data is NOT cloned, so don't change data after you've * passed it to the pubsub framework! */ constructor(topic: string, data?: any, headers?: Headers); /** * Perform a shallow clone of the message. * * I.e. the new message will share the same `data` as the source message, * so be careful when the data is an object: making changes to it will be * reflected in the old and new message. * * The headers (if any) are cloned into a new headers object. * * @return New message with same topic, same data and shallow clone of headers. */ clone(): Message; /** * Validate correctness of message properties, e.g. that topic is a string, * and header is either undefined or key-values. */ validate(): void; } export default Message;