type SyncFn = (data: unknown) => void; type AsyncFn = (data: unknown) => Promise; type Fn = SyncFn | AsyncFn; export type RawEvents = { [key: string]: Fn | { run: Fn; once?: boolean; }; }; /** * Types of Log Object shapes */ export type LogObject = { name: string; event: string; client_id: string; msg: string; on: Date; data: unknown; err: Error; }; /** * Logger Function type */ export type LogFn = (log: LogObject) => void; export type PubSubOptions = { /** * Custom logger function, will receive an instance of LogObject when an error is thrown */ logger?: LogFn; /** * Name of the pubsub (used in logs as well) */ name?: string; /** * Whether or not the default is for the last provided value to be stored. (if not passed = false) */ store?: boolean; }; declare class PubSub { #private; constructor(options?: PubSubOptions); /** * Getter returning the name of the pubsub. */ get name(): string; /** * Publish data for a specific event. * * An optional third parameter allows the producer to override the default storage behavior. * If storage is enabled, the published data is saved so that new subscribers receive it immediately. * * @param {string} event - Name of the event. * @param {unknown} data - (Optional) Data to publish. * @param {boolean?} store - (Optional) Override for storing this event’s data. */ publish(event: string, data?: unknown, store?: boolean): void; /** * Subscribes to one or more events as a client. * * After adding the subscription, if there is stored data for an event, * the new subscriber's callback is immediately invoked with that data. * * @param {RawEvents} events - Raw Events object to subscribe to. * @param {string?} client_id - Optional client id. If not provided one will be generated. * @param {boolean?} override - Defaults to true. If false, existing subscriptions for the same event are preserved. * @returns Client id if successful, or null for invalid input. */ subscribe(events: RawEvents, client_id?: string, override?: boolean): string | null; /** * Unsubscribes a client from specified event(s) or from all events if none are specified. * * @param {string} client_id - Client ID to unsubscribe. * @param {string|string[]?} event - (Optional) Unsubscribe only from these event(s). */ unsubscribe(client_id: string, event?: string | string[]): void; /** * Retrieve the client IDs subscribed to a single, multiple, or all events. * * @param {string|string[]?} event - Optional event or events array. */ clientIds(event?: string | string[]): Set; /** * Clear subscriptions for specific event(s) or all events. * * @param {string|string[]?} event - Events to clear. */ clear(event?: string | string[]): void; } export { PubSub, PubSub as default };