import IResultsProvider, { ResultsProviderFetchNextOptions } from '../result/IResultsProvider'; import { ArrowBatch } from '../result/utils'; /** * The minimal slice of the napi-binding `Statement` class that we * consume from JS. Defined locally (not imported from the binding's * d.ts) so the loader layer's loose `unknown` typing doesn't force * unsafe casts at every call site, and so unit tests can pass a stub. */ export interface KernelFetchHandle { fetchNextBatch(): Promise<{ ipcBytes: Buffer; } | null>; } /** * `IResultsProvider` that pulls Arrow IPC batches from the * kernel via the napi `Statement` handle and adapts them onto the * shape `ArrowResultConverter` already speaks * (`lib/result/utils.ts:22-25`). * * Each kernel `fetchNextBatch()` call returns a complete Arrow IPC * stream (schema header + 1 record-batch message) per the design * documented at `kernel-workflow/findings/arch/napi-binding/round2-methods-2026-05-15.md:46-60`. * We pass that buffer through as a single-element `batches: [ipcBytes]` * array — `RecordBatchReader.from(arrowBatch.batches)` inside the * converter (`lib/result/ArrowResultConverter.ts:119`) reads the * schema from the prefix and then the record-batch messages from the * remainder of the same buffer. * * We pre-parse the IPC bytes once here to extract `rowCount` (the * sum of `RecordBatch.numRows` across messages in the stream) because * the converter consumes that as an explicit field rather than * deriving it from the batch contents. See the comment in * `KernelArrowIpc.ts:decodeIpcBatch` for the cost rationale. */ export default class KernelResultsProvider implements IResultsProvider { private readonly statement; private prefetched?; private exhausted; constructor(statement: KernelFetchHandle); hasMore(): Promise; fetchNext(_options: ResultsProviderFetchNextOptions): Promise; private prime; }