1
1
// TypeScript definitions for @pgsql/parser
2
2
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 {
4
74
parse_tree?: any;
5
75
stderr_buffer?: string;
6
76
error?: {
@@ -13,12 +83,9 @@ export interface ParseResult {
13
83
};
14
84
}
15
85
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[];
22
89
23
90
export default Parser;
24
91
0 commit comments