import { F as FileStatus } from './index-DJQU6BUw.js'; export { D as DatasetRowsLoader, a as DryRunErr, b as DryRunOk, c as DryRunResult, d as DuckDBContextValue, e as DuckvizDBProvider, f as DuckvizDataset, L as LogType, P as ParsingConfig, S as SchemaColumn, T as TableInfo, U as UseAutoIngestOptions, g as dryRunQuery, p as pathToTableName, r as runIngest, u as useAutoIngest, h as useDuckDB, i as useDuckDBOrNull } from './index-DJQU6BUw.js'; import * as zustand from 'zustand'; import { PersistStorage } from 'zustand/middleware'; import * as duckdb from '@duckdb/duckdb-wasm'; import 'react/jsx-runtime'; import 'react'; /** Known Arrow/DuckDB internal keys that should be stripped from query results. */ declare const ARROW_INTERNAL_KEYS: Set; /** Recursively convert Arrow/DuckDB results to plain JS. Uses JSON round-trip to strip internals. */ declare function toCleanJSON(value: unknown): unknown; /** Recursively convert DuckDB/Arrow row values to plain JavaScript */ declare function toPlainValue(v: unknown): unknown; /** Convert nested value to rows for sub-table */ declare function toSubTableRows(val: unknown): Record[]; interface FileIngestionState { status: FileStatus; rowsIngested: number; error?: string; } interface IngestionStore { /** Per-file status keyed by file path */ fileStatuses: Map; /** Maps file path → DuckDB table names created from that file. * For multi-table imports (complex JSON), one path can have multiple tables. */ fileTableMap: Map; /** True if any file is in a non-terminal status */ isIngesting: boolean; /** Count of files that are done or errored */ filesProcessed: number; /** Total files tracked */ filesTotal: number; /** Last filesEpoch for which we cleared DuckDB tables. -1 = never. */ lastClearedEpoch: number; /** Update a single file's status (also adds the file if not tracked yet). */ setFileStatus: (path: string, status: FileStatus, rowsIngested?: number, error?: string) => void; /** Check if a file has been ingested (status is "done"). */ isFileIngested: (path: string) => boolean; /** Set the DuckDB table names created from a file path. */ setFileTables: (path: string, tableNames: string[]) => void; /** Get the DuckDB table names for a file path. */ getFileTables: (path: string) => string[]; /** Reset everything (e.g. when folder changes). */ reset: (epoch: number) => void; /** Remove a file from tracking (e.g. user cancelled ingestion). */ removeFileStatus: (path: string) => void; /** Remove non-terminal statuses (interrupted by unmount). */ cleanupInterrupted: () => void; /** Remove a file's table mapping. */ removeFileTables: (path: string) => void; } declare const useIngestionStore: zustand.UseBoundStore>; declare function hydrateIngestionStore(): Promise; declare function subscribeIngestionPersistence(): () => void; /** * Thin IndexedDB wrapper for persistence. * * Database: "duckviz-persist" * Object stores: * - "keyval" → Zustand store state (JSON strings) * - "blobs" → Parquet buffers, file ArrayBuffers */ declare function idbGet(store: string, key: string): Promise; declare function idbSet(store: string, key: string, value: unknown): Promise; declare function createZustandIDBStorage(): PersistStorage; declare function blobGet(key: string): Promise; declare function blobSet(key: string, value: unknown): Promise; declare function blobDelete(key: string): Promise; declare function blobKeys(): Promise; /** Check if any persisted file data exists (indicates a previous session). */ declare function hasPersistedSession(): Promise; /** * Verify both stores are empty — used by the Clear All flow to confirm the * clear actually landed before redirecting. Returns a summary so the UI can * show exact counts on failure. */ declare function getPersistedStateSize(): Promise<{ blobs: number; keyval: number; totalBytes: number | null; }>; /** * Clear all persisted state — blobs (files + parquet) and Zustand keyval. * * Uses a single multi-store transaction and awaits `oncomplete` (not the * per-request `onsuccess`), then explicitly closes the db. The previous * implementation ran two parallel `idbClear()` calls — each awaited * `request.onsuccess`, which fires BEFORE `transaction.oncomplete`, so the * helper returned with the IDBDatabase handle still open. A subsequent * `deleteAllPersistedState()` in the same microtask queue then fired * `indexedDB.deleteDatabase()` before the close ran → `onblocked` → * silently resolved → database never actually deleted → residual data * visible on the next page load. This was the root cause of "Clear All * Data requires two clicks". */ declare function clearAllPersistedState(): Promise; /** * Fully delete the IDB database and reclaim its quota. `clearAllPersistedState` * only empties records — the underlying database keeps its allocated pages, so * `navigator.storage.estimate()` keeps reporting the old footprint (what the * memory badge shows). This drops usage back to near-zero. * * Waits for `onsuccess` rather than bailing on `onblocked` — an `onblocked` * event is not a terminal state, it just means another connection is still * open. Resolving early there was the bug: the browser would fire `onblocked`, * we'd resolve without the delete actually happening, and the UI would reload * into stale data. A 3-second timeout prevents a truly stuck connection (e.g. * another tab holding the db open) from hanging the clear flow forever. */ declare function deleteAllPersistedState(): Promise; /** * DuckDB table persistence via Parquet export/import to IndexedDB. * * After ingestion completes for a table, we export it as a Parquet buffer * and store it in IndexedDB. On page load, we reimport all persisted tables * into DuckDB so queries work immediately. */ /** * Export a DuckDB table to Parquet and store the buffer in IndexedDB. * * If `sourcePath` is provided, the originating `file::` blob is stubbed * (metadata kept, bytes dropped) after the Parquet write succeeds. This * prevents holding two copies of the same logical dataset in IDB. */ declare function persistTable(db: duckdb.AsyncDuckDB, conn: duckdb.AsyncDuckDBConnection, tableName: string, sourcePath?: string): Promise; /** Remove a single table's Parquet buffer from IndexedDB. */ declare function removePersistedTable(tableName: string): Promise; /** Clear all persisted Parquet buffers from IndexedDB. */ declare function clearAllPersistedTables(): Promise; /** * File content persistence via IndexedDB. * * Stores file ArrayBuffer + metadata so File objects can be reconstructed * after a page refresh. Only persists files with ingestion status "done". */ /** Token returned by persistFiles so the caller can cancel an in-flight run. */ interface PersistHandle { cancel: () => void; } /** * Persist an array of files to IndexedDB with bounded concurrency. * * Returns a handle that lets the caller cancel an in-flight run (e.g. when * the user re-uploads before the previous folder finished persisting). * Cancellation only stops *new* files from being read; the at-most-N already * in flight will complete normally. */ declare function persistFiles(files: File[]): PersistHandle & { done: Promise; }; /** Restore all persisted files from IndexedDB as File objects. */ declare function restoreFiles(): Promise; /** Remove persisted files by their paths. */ declare function removePersistedFiles(paths: string[]): Promise; /** Clear all persisted file entries from IndexedDB. */ declare function clearAllPersistedFiles(): Promise; /** * JSON replacer/reviver for Map objects. * Maps are serialized as { __type: "Map", entries: [...] } so they can * round-trip through JSON.stringify / JSON.parse. */ declare function mapReplacer(_key: string, value: unknown): unknown; declare function mapReviver(_key: string, value: unknown): unknown; type DataQualityIssue = { type: "high-unparsed-ratio" | "oversized-fields" | "low-field-count" | "single-field-records" | "non-log-content" | "binary-content"; severity: "warning" | "error"; message: string; detail: string; }; type ValidationResult = { ok: boolean; issues: DataQualityIssue[]; }; /** * Validate parsed data quality before DuckDB ingestion. * Detects issues like multi-line records being split into individual lines, * embedded scripts/code producing oversized fields, and fragmented parsing. */ declare function validateParsedData(parsed: Record[], unparsed: string[]): ValidationResult; /** * Validate file content before sending to LLM for format detection. * Checks file extension and preview content for non-log patterns. * Returns null if the file looks fine, or a DataQualityIssue if problematic. */ declare function validateFileBeforeParsing(fileName: string, previewLines: string[]): DataQualityIssue | null; /** * Read a file and return the lines * @param file - The file to read * @param limit - The number of lines to read, or null/undefined to return all lines * @returns The lines of the file */ declare function readFile(file: File, limit?: number): Promise; /** * Create a file-ingestion Web Worker from the bundled IIFE code. * * Uses a blob URL so consumers don't need any bundler configuration — * the worker code is fully self-contained (papaparse, xlsx, fast-xml-parser * are all bundled into the IIFE at package build time). */ declare function createIngestionWorker(): Worker; export { ARROW_INTERNAL_KEYS, type DataQualityIssue, type FileIngestionState, FileStatus, type PersistHandle, blobDelete, blobGet, blobKeys, blobSet, clearAllPersistedFiles, clearAllPersistedState, clearAllPersistedTables, createIngestionWorker, createZustandIDBStorage, deleteAllPersistedState, getPersistedStateSize, hasPersistedSession, hydrateIngestionStore, idbGet, idbSet, mapReplacer, mapReviver, persistFiles, persistTable, readFile, removePersistedFiles, removePersistedTable, restoreFiles, subscribeIngestionPersistence, toCleanJSON, toPlainValue, toSubTableRows, useIngestionStore, validateFileBeforeParsing, validateParsedData };