import { ColumnType } from "./ts-rs/ColumnType.ts"; import { ViewConfig } from "./ts-rs/ViewConfig.ts"; import { ViewWindow } from "./ts-rs/ViewWindow.ts"; import type * as perspective from "../../dist/wasm/perspective-js.js"; /** * VirtualServer API for implementing custom data sources in JavaScript/WASM. * * The VirtualServer pattern allows you to create custom data sources that * integrate with Perspective's protocol. This is useful for: * - Connecting to external databases (DuckDB, PostgreSQL, etc.) * - Streaming data from APIs or message queues * - Implementing custom aggregation or transformation logic * - Creating data adapters without copying data into Perspective tables * * @module virtual_server */ export interface ServerFeatures { expressions?: boolean; } /** * Handler interface that you implement to provide custom data sources. * * All methods will be called by the VirtualServer when handling protocol * messages from Perspective clients. Methods can return values directly or * return Promises for asynchronous operations (e.g., database queries). */ export interface VirtualServerHandler { getHostedTables(): string[] | Promise; tableSchema(tableId: string): Record | Promise>; tableSize(tableId: string): number | Promise; tableMakeView(tableId: string, viewId: string, config: ViewConfig): void | Promise; viewDelete(viewId: string): void | Promise; viewGetData(viewId: string, config: ViewConfig, schema: Record, viewport: ViewWindow, dataSlice: perspective.VirtualDataSlice): void | Promise; viewSchema?(viewId: string, config?: ViewConfig): Record | Promise>; viewSize?(viewId: string): number | Promise; tableValidateExpression?(tableId: string, expression: string): ColumnType | Promise; viewGetMinMax?(viewId: string, columnName: string, config: ViewConfig): { min: any; max: any; } | Promise<{ min: any; max: any; }>; getFeatures?(): ServerFeatures | Promise; makeTable?(tableId: string, data: string | Uint8Array): void | Promise; } export declare function createMessageHandler(mod: typeof perspective, handler: VirtualServerHandler): MessagePort;