import type { MqttClient } from "mqtt"; /** What became of a publish. A failure is a value: publish() never rejects. */ export type PublishResult = { ok: true; topic: string; } | { ok: false; topic: string; error: Error; }; /** Where the bridge, its devices and their messages publish. The message is sent as JSON. */ export interface Publisher { publish(topic: string, message: object): Promise; } /** * Publishes to the broker through the client the bridge has at the time: a new one after disconnect() and connect(), * none before connect() and after disconnect(). Without a client the publish is refused. With a client that lost * its connection mqtt.js keeps the message and sends it after the reconnect, and the publish resolves then. */ export declare class MqttPublisher implements Publisher { private readonly client; constructor(client: () => MqttClient | null); publish(topic: string, message: object): Promise; } /** * Keeps what it is asked to publish, for tests and dry runs without a broker: * * const sent = new MemoryPublisher(); * device.publisher = sent; * await device.getStatusMessage(token, true).addPowerControllerProp(PowerController.ON).send(); * sent.published[0] // { topic: "//alexaResponce", message: { event, context } } */ export declare class MemoryPublisher implements Publisher { /** Oldest first. The message is what a subscriber gets after JSON.parse. */ readonly published: Array<{ topic: string; message: any; }>; /** Set it and every publish fails with this error, as a publish to a broker that is gone does. */ failWith: Error | null; publish(topic: string, message: object): Promise; } /** * send() as 1.x promises it: resolves with the topic, or with "" when nothing was published, and never rejects * (1.5.1 rejected, and a send() nobody caught killed the host on any broker hiccup). What went wrong goes to report: * the message cannot be built, the device is on no bridge, or the publish failed. */ export declare function send(publisher: Publisher | null, topic: string, build: () => object, report?: (err: Error) => void): Promise;