import { Observable } from "rxjs";
/**
 * @public
 */
type RequestMethod = 'doc' | 'query' | 'mutate' | 'presence_rollcall' | 'presence_announce' | 'presence_disconnect' | 'authorization';
/**
 * @public
 */
type SubscribeMethods = 'presence' | 'listen' | 'authorization';
/**
 * @public
 */
type RequestParams = Record<string, any>;
/**
 * @public
 */
interface BifurClient {
  heartbeats: Observable<Date>;
  listen: <T>(method: SubscribeMethods, params?: RequestParams) => Observable<T>;
  request: <T>(method: RequestMethod, params?: RequestParams) => Observable<T>;
}
/**
 * @public
 */
interface SanityClientLike {
  config(): {
    dataset: string;
    token?: string;
  };
  getUrl(path: string): string;
}
/**
 * @public
 */
interface BifurClientOptions {
  token$?: Observable<string | null>;
  getNextRequestId?: () => string;
}
/**
 * Create a Bifur client
 *
 * @param connection$ - An observable of WebSocket connections
 * @param options - Options for the client
 * @returns A Bifur client
 * @public
 */
declare const createClient: (connection$: Observable<WebSocket>, options?: BifurClientOptions) => BifurClient;
/**
 * Emitted when the socket errors or is closed by the other end.
 * `code` and `reason` come from the `CloseEvent` on `CONNECTION_CLOSED`.
 *
 * @public
 */
declare class WebSocketError extends Error {
  type: 'CONNECTION_ERROR' | 'CONNECTION_CLOSED';
  code: number | undefined;
  reason: string | undefined;
  constructor(message: string, type: 'CONNECTION_ERROR' | 'CONNECTION_CLOSED', code?: number, reason?: string);
}
/**
 * @public
 */
declare const ERROR_CODES: {
  readonly BAD_REQUEST: 4000;
  readonly UNAUTHORIZED: 4001;
  readonly NOT_FOUND: 4004;
  readonly INVALID_REQUEST: -32600;
  readonly METHOD_NOT_FOUND: -32601;
  readonly INVALID_PARAMS: -32602;
  readonly SUBSCRIPTION_NOT_FOUND: -32602;
  readonly PARSE_ERROR: -32700;
};
/**
 * @public
 */
type ERROR_CODES = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
/**
 * @public
 */
interface FromUrlOptions {
  timeout?: number;
  token$?: Observable<string | null>;
}
/**
 * Create a BifurClient from a WebSocket URL
 *
 * @param url - The URL to connect to
 * @param options - Options for the client
 * @returns A Bifur client instance
 * @public
 */
declare function fromUrl(url: string, options?: FromUrlOptions): BifurClient;
/**
 * Create a Bifur client from a `@sanity/client`-like instance
 *
 * @param client - A `@sanity/client`-like instance
 * @returns A Bifur client instance
 * @public
 */
declare function fromSanityClient(client: SanityClientLike): BifurClient;
export { type BifurClient, type BifurClientOptions, ERROR_CODES, FromUrlOptions, type RequestMethod, type RequestParams, type SanityClientLike, type SubscribeMethods, WebSocketError, createClient, fromSanityClient, fromUrl };
//# sourceMappingURL=index.d.ts.map