// TypeScript definitions for @pgsql/parser // Supported versions export type SupportedVersion = 13 | 14 | 15 | 16 | 17 | 18; // Version-specific type imports import type { ParseResult as ParseResult13, Node as Node13 } from './v13/types'; import type { ParseResult as ParseResult14, Node as Node14 } from './v14/types'; import type { ParseResult as ParseResult15, Node as Node15 } from './v15/types'; import type { ParseResult as ParseResult16, Node as Node16 } from './v16/types'; import type { ParseResult as ParseResult17, Node as Node17 } from './v17/types'; import type { ParseResult as ParseResult18, Node as Node18 } from './v18/types'; // Version-specific type mappings type ParseResultVersionMap = { 13: ParseResult13; 14: ParseResult14; 15: ParseResult15; 16: ParseResult16; 17: ParseResult17; 18: ParseResult18; }; type NodeVersionMap = { 13: Node13; 14: Node14; 15: Node15; 16: Node16; 17: Node17; 18: Node18; }; // Generic types with version constraints export type ParseResult = ParseResultVersionMap[Version]; export type Node = NodeVersionMap[Version]; // SQL Error types export interface SqlErrorDetails { message: string; cursorPosition: number; fileName?: string; functionName?: string; lineNumber?: number; context?: string; } export declare class SqlError extends Error { readonly name: 'SqlError'; sqlDetails?: SqlErrorDetails; constructor(message: string, details?: SqlErrorDetails); } // Parser options export interface ParserOptions { version?: Version; } // Main Parser class with generic version support export declare class Parser { readonly version: Version; readonly ready: Promise; constructor(options?: ParserOptions); /** * Parse SQL asynchronously. Returns a properly typed ParseResult for the parser version. * @throws {SqlError} if parsing fails */ parse(query: string): Promise>; /** * Parse SQL synchronously. Returns a properly typed ParseResult for the parser version. * @throws {SqlError} if parsing fails */ parseSync(query: string): ParseResult; /** * Load the parser module. This is called automatically on first parse, * but can be called manually to pre-load the WASM module. */ loadParser(): Promise; } // Legacy compatibility interface (for backward compatibility) export interface LegacyParseResult { parse_tree?: any; stderr_buffer?: string; error?: { message: string; funcname: string; filename: string; lineno: number; cursorpos: number; context?: string; }; } // Utility functions export declare function isSupportedVersion(version: unknown): version is SupportedVersion; export declare function getSupportedVersions(): readonly SupportedVersion[]; export default Parser; // Version-specific exports export * as v13 from './v13/index'; export * as v14 from './v14/index'; export * as v15 from './v15/index'; export * as v16 from './v16/index'; export * as v17 from './v17/index'; export * as v18 from './v18/index'; // Re-export types from the default version export * from './v18/types';