import { init, type Compression } from "./compression.ts"; import type { ClickHouseSettings } from "./settings.ts"; export { ClickHouseDateTime64, type ColumnDef, collectRows, type DecodeResult, encodeNative, type ExternalTableData, RecordBatch, rows, streamDecodeNative, streamEncodeNative, } from "@maxjustus/chttp/native"; import { type ExternalTableData } from "@maxjustus/chttp/native"; import { type CollectableAsyncGenerator } from "./util.ts"; export type { CollectableAsyncGenerator } from "./util.ts"; export type { QueryParamValue, QueryParams } from "./types.ts"; import type { QueryParams } from "./types.ts"; export type { Compression }; interface AuthConfig { username?: string; password?: string; } /** * Build a ClickHouse HTTP URL with query parameters. * @param params - Query params including ClickHouse settings (max_execution_time, etc.) * See: https://clickhouse.com/docs/en/operations/settings/settings */ declare function buildReqUrl(baseUrl: string, params: Record, auth?: AuthConfig): URL; interface ProgressInfo { blocksSent: number; bytesCompressed: number; bytesUncompressed: number; complete?: boolean; } /** Summary statistics from X-ClickHouse-Summary response header */ export interface QuerySummary { read_rows: string; read_bytes: string; written_rows: string; written_bytes: string; total_rows_to_read: string; result_rows: string; result_bytes: string; elapsed_ns: string; } /** Progress info from X-ClickHouse-Progress header */ export interface HttpProgress { read_rows: string; read_bytes: string; total_rows_to_read: string; written_rows?: string; written_bytes?: string; elapsed_ns?: string; } /** Packet types yielded by query() - mirrors TCP client pattern */ export type QueryPacket = { type: "Progress"; progress: HttpProgress; } | { type: "Data"; chunk: Uint8Array; } | { type: "Summary"; summary: QuerySummary; queryId: string; }; /** Result from insert() with metadata */ export interface InsertResult { summary: QuerySummary; queryId: string; } export interface InsertOptions { baseUrl?: string; /** Compression method: "lz4" (default), "zstd", or false */ compression?: Compression; /** Size in bytes for the compression buffer (default: 1MB) */ bufferSize?: number; /** Byte threshold to trigger compression flush (default: bufferSize - 2048) */ threshold?: number; onProgress?: (progress: ProgressInfo) => void; auth?: AuthConfig; /** AbortSignal for manual cancellation */ signal?: AbortSignal; /** Request timeout in milliseconds */ timeout?: number; /** ClickHouse settings applied to this insert */ settings?: ClickHouseSettings; /** Query parameters for parameterized queries like SELECT {x:UInt64} */ params?: QueryParams; /** Custom query ID for tracking in system.query_log and KILL QUERY */ queryId?: string; } type InsertData = Uint8Array | Uint8Array[] | AsyncIterable | Iterable; declare function insert(query: string, data: InsertData, sessionId: string, options?: InsertOptions): Promise; /** * Convert objects to JSONEachRow format as Uint8Array chunks. * Use with insert() for JSON data. */ declare function streamEncodeJsonEachRow(data: Iterable): Generator; declare function streamEncodeJsonEachRow(data: AsyncIterable): AsyncGenerator; /** Data for an HTTP external table */ export type HttpExternalTableData = string | Uint8Array | AsyncIterable; /** An external table to send via HTTP multipart/form-data */ export interface HttpExternalTable { /** Column structure, e.g. "id UInt32, name String" */ structure: string; /** Data format (default: TabSeparated) */ format?: string; /** The actual data */ data: HttpExternalTableData; } /** * Input for HTTP external tables. * Accepts RecordBatch (schema auto-extracted), iterables of RecordBatch, or explicit HttpExternalTable. */ export type HttpExternalTableInput = ExternalTableData | HttpExternalTable; export interface QueryOptions { baseUrl?: string; auth?: AuthConfig; /** Compression method for response: "lz4" (default), "zstd", or false */ compression?: Compression; /** * Compress query body using HTTP Content-Encoding. * - "zstd": ZSTD compression (recommended, works with native and WASM) * - "lz4": LZ4 frame compression (requires lz4-napi, not available in WASM builds) * Requires server setting: enable_http_compression=1 */ compressQuery?: "zstd" | "lz4"; /** AbortSignal for manual cancellation */ signal?: AbortSignal; /** Request timeout in milliseconds */ timeout?: number; /** Client version string (e.g. "24.8") or numeric revision */ clientVersion?: string | number; /** ClickHouse settings applied to this query */ settings?: ClickHouseSettings; /** Query parameters for parameterized queries like SELECT {x:UInt64} */ params?: QueryParams; /** External tables to send with the query (RecordBatch, iterables, or HttpExternalTable) */ externalTables?: Record; /** Custom query ID for tracking in system.query_log and KILL QUERY */ queryId?: string; } declare function query(sql: string, sessionId: string, options?: QueryOptions & Record): CollectableAsyncGenerator; /** Input type for stream helpers - accepts query() result or any async iterable of packets */ type QueryInput = AsyncIterable; /** Extract Data chunks from packet stream */ declare function dataChunks(input: QueryInput): AsyncGenerator; /** * Buffer byte chunks, decode to text, and yield complete lines. * * @example * for await (const line of streamLines(query("SELECT ...", session, config))) { * console.log(line); * } */ declare function streamLines(input: QueryInput, delimiter?: string): AsyncGenerator; /** * Buffer byte chunks, split by newlines, and parse as JSON. * Use with query() for JSONEachRow format. * * @example * for await (const row of streamDecodeJsonEachRow(query("SELECT ...", session, config))) { * console.log(row.id, row.name); * } */ declare function streamDecodeJsonEachRow(input: QueryInput): AsyncGenerator; /** * Decode bytes to text strings with streaming support. * * @example * for await (const text of streamText(query("SELECT ...", session, config))) { * console.log(text); * } */ declare function streamText(input: QueryInput): AsyncGenerator; /** * Collect all chunks into a single Uint8Array. * * @example * const data = await collectBytes(query("SELECT ...", session, config)); * const result = await decodeNative(data); */ declare function collectBytes(input: QueryInput): Promise; /** * Collect all bytes and decode to a single string. * * @example * const json = await collectText(query("SELECT ...", session, config)); * const data = JSON.parse(json); */ declare function collectText(input: QueryInput): Promise; /** * collect all JSON lines into an array of objects. * * @example * const rows = await collectJsonEachRow<{ id: number }>(query("SELECT ...", session, config)); */ declare function collectJsonEachRow(input: QueryInput): Promise; export { init, insert, query, buildReqUrl, streamEncodeJsonEachRow, streamText, streamLines, streamDecodeJsonEachRow, collectBytes, collectText, collectJsonEachRow, dataChunks, }; //# sourceMappingURL=client.d.ts.map