/**
 * Forma HTTP - Fetch
 *
 * Typed fetch wrapper with reactive signal integration.
 * Zero dependencies — native browser APIs only.
 */
interface FetchOptions<T> extends Omit<RequestInit, 'signal'> {
    base?: string;
    params?: Record<string, string>;
    timeout?: number;
    transform?: (data: unknown) => T;
}
interface FetchResult<T> {
    data: () => T | null;
    error: () => Error | null;
    loading: () => boolean;
    refetch: () => Promise<void>;
    abort: () => void;
}
/**
 * Create a reactive fetch that exposes data/error/loading as signals.
 *
 * If `url` is a signal getter (function), an effect auto-refetches when it
 * changes.
 *
 * ```ts
 * const { data, loading, error, refetch, abort } = createFetch<User[]>('/api/users');
 * ```
 */
declare function createFetch<T>(url: string | (() => string), options?: FetchOptions<T>): FetchResult<T>;
/**
 * One-shot fetch that returns parsed JSON.
 *
 * ```ts
 * const users = await fetchJSON<User[]>('/api/users');
 * ```
 */
declare function fetchJSON<T>(url: string, options?: RequestInit): Promise<T>;

/**
 * Forma HTTP - Server-Sent Events
 *
 * Reactive SSE wrapper with signal integration.
 * Zero dependencies — native browser APIs only.
 */
interface SSEOptions<T = unknown> {
    withCredentials?: boolean;
    headers?: Record<string, string>;
    /** Custom parser for incoming messages. Defaults to JSON.parse with raw data fallback. */
    parse?: (data: string) => T;
}
interface SSEConnection<T = unknown> {
    data: () => T | null;
    error: () => Event | null;
    connected: () => boolean;
    close: () => void;
    on(event: string, handler: (data: unknown) => void): () => void;
}
/**
 * Create a reactive Server-Sent Events connection.
 *
 * ```ts
 * const sse = createSSE<{ message: string }>('/api/events');
 * createEffect(() => {
 *   const msg = sse.data();
 *   if (msg) console.log(msg.message);
 * });
 * ```
 */
declare function createSSE<T = unknown>(url: string, options?: SSEOptions<T>): SSEConnection<T>;

/**
 * Forma HTTP - WebSocket
 *
 * Reactive WebSocket wrapper with auto-reconnect and signal integration.
 * Zero dependencies — native browser APIs only.
 */
type WSStatus = 'connecting' | 'open' | 'closed' | 'error';
interface WSOptions<TReceive = unknown> {
    protocols?: string | string[];
    reconnect?: boolean;
    /** The cap of the first reconnect delay, in ms (default 1000); it doubles each attempt. */
    reconnectInterval?: number;
    maxReconnects?: number;
    /**
     * The uniform source in [0, 1) the reconnect delay is drawn from. Defaults
     * to `Math.random`; a test passes a seeded one to replay a run. A value that
     * is not a function, or a draw outside [0, 1), falls back to `Math.random`.
     */
    random?: () => number;
    /** Custom parser for incoming messages. Defaults to JSON.parse with raw data fallback. */
    parse?: (data: string) => TReceive;
}
interface WSConnection<TSend = unknown, TReceive = unknown> {
    data: () => TReceive | null;
    status: () => WSStatus;
    send(data: TSend): void;
    close(): void;
    on(handler: (data: TReceive) => void): () => void;
}
/**
 * Create a reactive WebSocket connection with auto-reconnect.
 *
 * A closed connection is retried up to `maxReconnects` times. The n-th retry
 * waits a delay drawn uniformly between 0 and `reconnectInterval * 2^(n-1)`
 * (full jitter), so the clients of a server that restarts do not all reconnect
 * in the same instant. A successful open restarts the count.
 *
 * Verified by: src/http/__tests__/ws-reconnect.test.ts > "with a seeded random source, the n-th reconnect delay lies between 0 and 2^(n-1) s and differs across simulated clients"
 * Verified by: src/http/__tests__/ws-reconnect.test.ts > "a successful connection restarts the cap at reconnectInterval"
 *
 * ```ts
 * const ws = createWebSocket<string, ChatMessage>('wss://chat.example.com');
 * ws.send('hello');
 * createEffect(() => {
 *   const msg = ws.data();
 *   if (msg) console.log(msg);
 * });
 * ```
 */
declare function createWebSocket<TSend = unknown, TReceive = unknown>(url: string, options?: WSOptions<TReceive>): WSConnection<TSend, TReceive>;

export { type FetchOptions, type FetchResult, type SSEConnection, type SSEOptions, type WSConnection, type WSOptions, type WSStatus, createFetch, createSSE, createWebSocket, fetchJSON };
