11// TypeScript definitions for @pgsql/parser
22
3- export interface ParseResult {
3+ // Supported versions
4+ export type SupportedVersion = ${VERSION_UNION};
5+
6+ // Version-specific type imports
7+ ${VERSION_TYPE_IMPORTS}
8+
9+ // Version-specific type mappings
10+ type ParseResultVersionMap = {
11+ ${VERSION_PARSE_RESULT_MAP}
12+ };
13+
14+ type NodeVersionMap = {
15+ ${VERSION_NODE_MAP}
16+ };
17+
18+ // Generic types with version constraints
19+ export type ParseResult<Version extends SupportedVersion = SupportedVersion> =
20+ ParseResultVersionMap[Version];
21+
22+ export type Node<Version extends SupportedVersion = SupportedVersion> =
23+ NodeVersionMap[Version];
24+
25+ // SQL Error types
26+ export interface SqlErrorDetails {
27+ message: string;
28+ cursorPosition: number;
29+ fileName?: string;
30+ functionName?: string;
31+ lineNumber?: number;
32+ context?: string;
33+ }
34+
35+ export declare class SqlError extends Error {
36+ readonly name: 'SqlError';
37+ sqlDetails?: SqlErrorDetails;
38+ constructor(message: string, details?: SqlErrorDetails);
39+ }
40+
41+ // Parser options
42+ export interface ParserOptions<Version extends SupportedVersion> {
43+ version?: Version;
44+ }
45+
46+ // Main Parser class with generic version support
47+ export declare class Parser<Version extends SupportedVersion = ${DEFAULT_VERSION}> {
48+ readonly version: Version;
49+ readonly ready: Promise<void>;
50+
51+ constructor(options?: ParserOptions<Version>);
52+
53+ /**
54+ * Parse SQL asynchronously. Returns a properly typed ParseResult for the parser version.
55+ * @throws {SqlError} if parsing fails
56+ */
57+ parse(query: string): Promise<ParseResult<Version>>;
58+
59+ /**
60+ * Parse SQL synchronously. Returns a properly typed ParseResult for the parser version.
61+ * @throws {SqlError} if parsing fails
62+ */
63+ parseSync(query: string): ParseResult<Version>;
64+
65+ /**
66+ * Load the parser module. This is called automatically on first parse,
67+ * but can be called manually to pre-load the WASM module.
68+ */
69+ loadParser(): Promise<void>;
70+ }
71+
72+ // Legacy compatibility interface (for backward compatibility)
73+ export interface LegacyParseResult {
474 parse_tree?: any;
575 stderr_buffer?: string;
676 error?: {
@@ -13,12 +83,9 @@ export interface ParseResult {
1383 };
1484}
1585
16- export declare class Parser {
17- constructor(version?: ${VERSION_UNION});
18- loadParser(): Promise<void>;
19- parse(query: string): Promise<ParseResult>;
20- parseSync(query: string): ParseResult;
21- }
86+ // Utility functions
87+ export declare function isSupportedVersion(version: unknown): version is SupportedVersion;
88+ export declare function getSupportedVersions(): readonly SupportedVersion[];
2289
2390export default Parser;
2491
0 commit comments