import { JsonValue, Jsonify } from 'type-fest'; declare type RuntimeContext = 'devtools' | 'background' | 'popup' | 'options' | 'content-script' | 'window'; interface Endpoint { context: RuntimeContext; tabId: number; frameId?: number; } interface BridgeMessage { sender: Endpoint; id: string; data: T; timestamp: number; } declare type OnMessageCallback = (message: BridgeMessage) => R | Promise; interface InternalMessage { origin: Endpoint; destination: Endpoint; transactionId: string; hops: string[]; messageID: string; messageType: 'message' | 'reply'; err?: JsonValue; data?: JsonValue | void; timestamp: number; } interface StreamInfo { streamId: string; channel: string; endpoint: Endpoint; } interface HybridUnsubscriber { (): void; dispose: () => void; close: () => void; } declare type Destination = Endpoint | RuntimeContext | string; declare const ProtocolWithReturnSymbol: unique symbol; interface ProtocolWithReturn { data: Jsonify; return: Jsonify; /** * Type differentiator only. */ [ProtocolWithReturnSymbol]: true; } /** * Extendable by user. */ interface ProtocolMap { } declare type DataTypeKey = keyof ProtocolMap extends never ? string : keyof ProtocolMap; declare type GetDataType = K extends keyof ProtocolMap ? ProtocolMap[K] extends (...args: infer Args) => any ? Args['length'] extends 0 ? undefined : Args[0] : ProtocolMap[K] extends ProtocolWithReturn ? Data : ProtocolMap[K] : Fallback; declare type GetReturnType = K extends keyof ProtocolMap ? ProtocolMap[K] extends (...args: any[]) => infer R ? R : ProtocolMap[K] extends ProtocolWithReturn ? Return : void : Fallback; export { BridgeMessage as B, Destination as D, Endpoint as E, GetDataType as G, HybridUnsubscriber as H, InternalMessage as I, OnMessageCallback as O, ProtocolWithReturn as P, RuntimeContext as R, StreamInfo as S, ProtocolMap as a, DataTypeKey as b, GetReturnType as c };