sqlparser-rs 0.60.0-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/dialects.js +191 -0
- package/dist/cjs/dialects.js.map +1 -0
- package/dist/cjs/index.js +81 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/parser.js +264 -0
- package/dist/cjs/parser.js.map +1 -0
- package/dist/cjs/types/ast.js +10 -0
- package/dist/cjs/types/ast.js.map +1 -0
- package/dist/cjs/types/errors.js +49 -0
- package/dist/cjs/types/errors.js.map +1 -0
- package/dist/cjs/types/index.js +19 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/esm/dialects.js +174 -0
- package/dist/esm/dialects.js.map +1 -0
- package/dist/esm/index.js +47 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/parser.js +226 -0
- package/dist/esm/parser.js.map +1 -0
- package/dist/esm/types/ast.js +9 -0
- package/dist/esm/types/ast.js.map +1 -0
- package/dist/esm/types/errors.js +44 -0
- package/dist/esm/types/errors.js.map +1 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/types/dialects.d.ts +112 -0
- package/dist/types/dialects.d.ts.map +1 -0
- package/dist/types/index.d.ts +46 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/parser.d.ts +130 -0
- package/dist/types/parser.d.ts.map +1 -0
- package/dist/types/types/ast.d.ts +1097 -0
- package/dist/types/types/ast.d.ts.map +1 -0
- package/dist/types/types/errors.d.ts +25 -0
- package/dist/types/types/errors.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL Dialects
|
|
3
|
+
*
|
|
4
|
+
* Each dialect class represents a specific SQL dialect supported by the parser.
|
|
5
|
+
* These are thin wrappers that provide type safety and a clean API.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Generic SQL dialect - accepts most SQL syntax
|
|
9
|
+
*/
|
|
10
|
+
export class GenericDialect {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.name = 'generic';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* ANSI SQL standard dialect
|
|
17
|
+
*/
|
|
18
|
+
export class AnsiDialect {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.name = 'ansi';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* MySQL dialect
|
|
25
|
+
*/
|
|
26
|
+
export class MySqlDialect {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.name = 'mysql';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* PostgreSQL dialect
|
|
33
|
+
*/
|
|
34
|
+
export class PostgreSqlDialect {
|
|
35
|
+
constructor() {
|
|
36
|
+
this.name = 'postgresql';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* SQLite dialect
|
|
41
|
+
*/
|
|
42
|
+
export class SQLiteDialect {
|
|
43
|
+
constructor() {
|
|
44
|
+
this.name = 'sqlite';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Snowflake dialect
|
|
49
|
+
*/
|
|
50
|
+
export class SnowflakeDialect {
|
|
51
|
+
constructor() {
|
|
52
|
+
this.name = 'snowflake';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Amazon Redshift dialect
|
|
57
|
+
*/
|
|
58
|
+
export class RedshiftDialect {
|
|
59
|
+
constructor() {
|
|
60
|
+
this.name = 'redshift';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Microsoft SQL Server dialect
|
|
65
|
+
*/
|
|
66
|
+
export class MsSqlDialect {
|
|
67
|
+
constructor() {
|
|
68
|
+
this.name = 'mssql';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* ClickHouse dialect
|
|
73
|
+
*/
|
|
74
|
+
export class ClickHouseDialect {
|
|
75
|
+
constructor() {
|
|
76
|
+
this.name = 'clickhouse';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Google BigQuery dialect
|
|
81
|
+
*/
|
|
82
|
+
export class BigQueryDialect {
|
|
83
|
+
constructor() {
|
|
84
|
+
this.name = 'bigquery';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* DuckDB dialect
|
|
89
|
+
*/
|
|
90
|
+
export class DuckDbDialect {
|
|
91
|
+
constructor() {
|
|
92
|
+
this.name = 'duckdb';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Databricks dialect
|
|
97
|
+
*/
|
|
98
|
+
export class DatabricksDialect {
|
|
99
|
+
constructor() {
|
|
100
|
+
this.name = 'databricks';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Apache Hive dialect
|
|
105
|
+
*/
|
|
106
|
+
export class HiveDialect {
|
|
107
|
+
constructor() {
|
|
108
|
+
this.name = 'hive';
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* All supported dialect names
|
|
113
|
+
*/
|
|
114
|
+
export const SUPPORTED_DIALECTS = [
|
|
115
|
+
'generic',
|
|
116
|
+
'ansi',
|
|
117
|
+
'mysql',
|
|
118
|
+
'postgresql',
|
|
119
|
+
'sqlite',
|
|
120
|
+
'snowflake',
|
|
121
|
+
'redshift',
|
|
122
|
+
'mssql',
|
|
123
|
+
'clickhouse',
|
|
124
|
+
'bigquery',
|
|
125
|
+
'duckdb',
|
|
126
|
+
'databricks',
|
|
127
|
+
'hive',
|
|
128
|
+
];
|
|
129
|
+
/**
|
|
130
|
+
* Map of dialect names to dialect classes
|
|
131
|
+
*/
|
|
132
|
+
const DIALECT_MAP = {
|
|
133
|
+
generic: GenericDialect,
|
|
134
|
+
ansi: AnsiDialect,
|
|
135
|
+
mysql: MySqlDialect,
|
|
136
|
+
postgresql: PostgreSqlDialect,
|
|
137
|
+
sqlite: SQLiteDialect,
|
|
138
|
+
snowflake: SnowflakeDialect,
|
|
139
|
+
redshift: RedshiftDialect,
|
|
140
|
+
mssql: MsSqlDialect,
|
|
141
|
+
clickhouse: ClickHouseDialect,
|
|
142
|
+
bigquery: BigQueryDialect,
|
|
143
|
+
duckdb: DuckDbDialect,
|
|
144
|
+
databricks: DatabricksDialect,
|
|
145
|
+
hive: HiveDialect,
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Create a dialect instance from a string name
|
|
149
|
+
*
|
|
150
|
+
* @param name - The name of the dialect (case-insensitive)
|
|
151
|
+
* @returns A dialect instance, or undefined if the dialect is not recognized
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* const dialect = dialectFromString('postgresql');
|
|
156
|
+
* if (dialect) {
|
|
157
|
+
* const ast = Parser.parse('SELECT 1', dialect);
|
|
158
|
+
* }
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export function dialectFromString(name) {
|
|
162
|
+
const normalized = name.toLowerCase();
|
|
163
|
+
// Handle common aliases
|
|
164
|
+
const aliasMap = {
|
|
165
|
+
postgres: 'postgresql',
|
|
166
|
+
pg: 'postgresql',
|
|
167
|
+
sqlserver: 'mssql',
|
|
168
|
+
duck: 'duckdb',
|
|
169
|
+
};
|
|
170
|
+
const dialectName = aliasMap[normalized] ?? normalized;
|
|
171
|
+
const DialectClass = DIALECT_MAP[dialectName];
|
|
172
|
+
return DialectClass ? new DialectClass() : undefined;
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=dialects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialects.js","sourceRoot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providing
|
|
5
|
+
* a fast and accurate SQL parser for JavaScript and TypeScript.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { Parser, GenericDialect, PostgreSqlDialect } from 'sqlparser-rs';
|
|
10
|
+
*
|
|
11
|
+
* // Simple parsing
|
|
12
|
+
* const statements = await Parser.parse('SELECT * FROM users', new GenericDialect());
|
|
13
|
+
*
|
|
14
|
+
* // With specific dialect
|
|
15
|
+
* const pgStatements = await Parser.parse(
|
|
16
|
+
* 'SELECT * FROM users WHERE id = $1',
|
|
17
|
+
* new PostgreSqlDialect()
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* // Builder pattern with options
|
|
21
|
+
* const parser = new Parser(new PostgreSqlDialect())
|
|
22
|
+
* .withRecursionLimit(50)
|
|
23
|
+
* .withOptions({ trailingCommas: true });
|
|
24
|
+
*
|
|
25
|
+
* const ast = await parser.parseAsync('SELECT * FROM users');
|
|
26
|
+
*
|
|
27
|
+
* // Format SQL
|
|
28
|
+
* const formatted = await Parser.format('select * from users', new GenericDialect());
|
|
29
|
+
* // Returns: "SELECT * FROM users"
|
|
30
|
+
*
|
|
31
|
+
* // Validate SQL
|
|
32
|
+
* try {
|
|
33
|
+
* await Parser.validate('SELECT * FRO users', new GenericDialect());
|
|
34
|
+
* } catch (e) {
|
|
35
|
+
* console.log('Invalid SQL:', e.message);
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @packageDocumentation
|
|
40
|
+
*/
|
|
41
|
+
// Parser
|
|
42
|
+
export { Parser, initWasm } from './parser';
|
|
43
|
+
// Dialects
|
|
44
|
+
export { GenericDialect, AnsiDialect, MySqlDialect, PostgreSqlDialect, SQLiteDialect, SnowflakeDialect, RedshiftDialect, MsSqlDialect, ClickHouseDialect, BigQueryDialect, DuckDbDialect, DatabricksDialect, HiveDialect, dialectFromString, SUPPORTED_DIALECTS, } from './dialects';
|
|
45
|
+
// Types
|
|
46
|
+
export * from './types';
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,SAAS;AACT,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAG5C,WAAW;AACX,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAGpB,QAAQ;AACR,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { GenericDialect } from './dialects';
|
|
2
|
+
import { ParserError, WasmInitError } from './types/errors';
|
|
3
|
+
// Global WASM module instance
|
|
4
|
+
let wasmModule = null;
|
|
5
|
+
let wasmInitPromise = null;
|
|
6
|
+
/**
|
|
7
|
+
* Initialize the WASM module
|
|
8
|
+
* This is called automatically when needed, but can be called manually for eager loading
|
|
9
|
+
*/
|
|
10
|
+
export async function initWasm() {
|
|
11
|
+
await getWasmModule();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get or initialize the WASM module
|
|
15
|
+
*/
|
|
16
|
+
async function getWasmModule() {
|
|
17
|
+
if (wasmModule) {
|
|
18
|
+
return wasmModule;
|
|
19
|
+
}
|
|
20
|
+
if (wasmInitPromise) {
|
|
21
|
+
return wasmInitPromise;
|
|
22
|
+
}
|
|
23
|
+
wasmInitPromise = (async () => {
|
|
24
|
+
try {
|
|
25
|
+
// Try to load the WASM module
|
|
26
|
+
// Use dynamic path to avoid TypeScript path resolution issues
|
|
27
|
+
// The path is relative to the compiled output in dist/cjs or dist/esm
|
|
28
|
+
const wasmPath = '../../wasm/sqlparser_rs_wasm.js';
|
|
29
|
+
const wasm = await import(/* webpackIgnore: true */ wasmPath);
|
|
30
|
+
wasmModule = wasm;
|
|
31
|
+
return wasmModule;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new WasmInitError(`Failed to initialize WASM module: ${error instanceof Error ? error.message : String(error)}`);
|
|
35
|
+
}
|
|
36
|
+
})();
|
|
37
|
+
return wasmInitPromise;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get the WASM module synchronously (throws if not initialized)
|
|
41
|
+
*/
|
|
42
|
+
function getWasmModuleSync() {
|
|
43
|
+
if (!wasmModule) {
|
|
44
|
+
throw new WasmInitError('WASM module not initialized. Call initWasm() first or use async methods.');
|
|
45
|
+
}
|
|
46
|
+
return wasmModule;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* SQL Parser
|
|
50
|
+
*
|
|
51
|
+
* Parses SQL statements into an Abstract Syntax Tree (AST).
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { Parser, PostgreSqlDialect } from 'sqlparser-rs';
|
|
56
|
+
*
|
|
57
|
+
* // Simple parsing
|
|
58
|
+
* const statements = await Parser.parse('SELECT * FROM users', new PostgreSqlDialect());
|
|
59
|
+
*
|
|
60
|
+
* // With builder pattern
|
|
61
|
+
* const parser = new Parser(new PostgreSqlDialect())
|
|
62
|
+
* .withRecursionLimit(50)
|
|
63
|
+
* .withOptions({ trailingCommas: true });
|
|
64
|
+
*
|
|
65
|
+
* const ast = await parser.parseAsync('SELECT * FROM users');
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export class Parser {
|
|
69
|
+
/**
|
|
70
|
+
* Create a new parser instance
|
|
71
|
+
*
|
|
72
|
+
* @param dialect - The SQL dialect to use (defaults to GenericDialect)
|
|
73
|
+
*/
|
|
74
|
+
constructor(dialect = new GenericDialect()) {
|
|
75
|
+
this.dialect = dialect;
|
|
76
|
+
this.options = {};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Set the recursion limit for parsing nested expressions
|
|
80
|
+
*
|
|
81
|
+
* @param limit - Maximum recursion depth
|
|
82
|
+
* @returns This parser instance for chaining
|
|
83
|
+
*/
|
|
84
|
+
withRecursionLimit(limit) {
|
|
85
|
+
this.options.recursionLimit = limit;
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Set parser options
|
|
90
|
+
*
|
|
91
|
+
* @param options - Parser options
|
|
92
|
+
* @returns This parser instance for chaining
|
|
93
|
+
*/
|
|
94
|
+
withOptions(options) {
|
|
95
|
+
this.options = { ...this.options, ...options };
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Parse SQL statements asynchronously
|
|
100
|
+
*
|
|
101
|
+
* @param sql - SQL string to parse
|
|
102
|
+
* @returns Array of parsed statements
|
|
103
|
+
*/
|
|
104
|
+
async parseAsync(sql) {
|
|
105
|
+
const wasm = await getWasmModule();
|
|
106
|
+
return this.parseWithWasm(wasm, sql);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Parse SQL statements synchronously
|
|
110
|
+
* Requires WASM module to be initialized first via initWasm()
|
|
111
|
+
*
|
|
112
|
+
* @param sql - SQL string to parse
|
|
113
|
+
* @returns Array of parsed statements
|
|
114
|
+
*/
|
|
115
|
+
parseSync(sql) {
|
|
116
|
+
const wasm = getWasmModuleSync();
|
|
117
|
+
return this.parseWithWasm(wasm, sql);
|
|
118
|
+
}
|
|
119
|
+
parseWithWasm(wasm, sql) {
|
|
120
|
+
try {
|
|
121
|
+
const hasOptions = Object.keys(this.options).length > 0;
|
|
122
|
+
if (hasOptions) {
|
|
123
|
+
const result = wasm.parse_sql_with_options(this.dialect.name, sql, this.options);
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const result = wasm.parse_sql(this.dialect.name, sql);
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw ParserError.fromWasmError(error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// ============================================================================
|
|
136
|
+
// Static methods for simple one-off parsing
|
|
137
|
+
// ============================================================================
|
|
138
|
+
/**
|
|
139
|
+
* Parse SQL statements (async)
|
|
140
|
+
*
|
|
141
|
+
* @param sql - SQL string to parse
|
|
142
|
+
* @param dialect - SQL dialect to use
|
|
143
|
+
* @returns Array of parsed statements
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const statements = await Parser.parse('SELECT 1', new GenericDialect());
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
static async parse(sql, dialect = new GenericDialect()) {
|
|
151
|
+
const parser = new Parser(dialect);
|
|
152
|
+
return parser.parseAsync(sql);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Parse SQL and return the AST as a JSON string (async)
|
|
156
|
+
*
|
|
157
|
+
* @param sql - SQL string to parse
|
|
158
|
+
* @param dialect - SQL dialect to use
|
|
159
|
+
* @returns JSON string representation of the AST
|
|
160
|
+
*/
|
|
161
|
+
static async parseToJson(sql, dialect = new GenericDialect()) {
|
|
162
|
+
const wasm = await getWasmModule();
|
|
163
|
+
try {
|
|
164
|
+
return wasm.parse_sql_to_json_string(dialect.name, sql);
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
throw ParserError.fromWasmError(error);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Parse SQL and return a formatted string representation (async)
|
|
172
|
+
*
|
|
173
|
+
* @param sql - SQL string to parse
|
|
174
|
+
* @param dialect - SQL dialect to use
|
|
175
|
+
* @returns String representation of the parsed SQL
|
|
176
|
+
*/
|
|
177
|
+
static async parseToString(sql, dialect = new GenericDialect()) {
|
|
178
|
+
const wasm = await getWasmModule();
|
|
179
|
+
try {
|
|
180
|
+
return wasm.parse_sql_to_string(dialect.name, sql);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throw ParserError.fromWasmError(error);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Format SQL by parsing and regenerating it (round-trip)
|
|
188
|
+
*
|
|
189
|
+
* @param sql - SQL string to format
|
|
190
|
+
* @param dialect - SQL dialect to use
|
|
191
|
+
* @returns Formatted SQL string
|
|
192
|
+
*/
|
|
193
|
+
static async format(sql, dialect = new GenericDialect()) {
|
|
194
|
+
const wasm = await getWasmModule();
|
|
195
|
+
try {
|
|
196
|
+
return wasm.format_sql(dialect.name, sql);
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
throw ParserError.fromWasmError(error);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Validate SQL syntax without returning the full AST
|
|
204
|
+
*
|
|
205
|
+
* @param sql - SQL string to validate
|
|
206
|
+
* @param dialect - SQL dialect to use
|
|
207
|
+
* @returns true if valid, throws ParserError if invalid
|
|
208
|
+
*/
|
|
209
|
+
static async validate(sql, dialect = new GenericDialect()) {
|
|
210
|
+
const wasm = await getWasmModule();
|
|
211
|
+
try {
|
|
212
|
+
return wasm.validate_sql(dialect.name, sql);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
throw ParserError.fromWasmError(error);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get the list of supported dialect names
|
|
220
|
+
*/
|
|
221
|
+
static async getSupportedDialects() {
|
|
222
|
+
const wasm = await getWasmModule();
|
|
223
|
+
return wasm.get_supported_dialects();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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IAED;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAW,EAAE,UAAmB,IAAI,cAAc,EAAE;QACtE,MAAM,IAAI,GAAG,MAAM,aAAa,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC5C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAW,EAAE,UAAmB,IAAI,cAAc,EAAE;QACxE,MAAM,IAAI,GAAG,MAAM,aAAa,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,oBAAoB;QAC/B,MAAM,IAAI,GAAG,MAAM,aAAa,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC,sBAAsB,EAAE,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type definitions for sqlparser-rs AST
|
|
3
|
+
*
|
|
4
|
+
* These types mirror the Rust AST structure from the sqlparser crate.
|
|
5
|
+
* The AST is serialized as JSON from Rust, so these types represent
|
|
6
|
+
* the JSON structure.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../../src/types/ast.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when SQL parsing fails
|
|
3
|
+
*/
|
|
4
|
+
export class ParserError extends Error {
|
|
5
|
+
constructor(message, location) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'ParserError';
|
|
8
|
+
this.location = location;
|
|
9
|
+
// Maintain proper stack trace in V8 environments
|
|
10
|
+
if (Error.captureStackTrace) {
|
|
11
|
+
Error.captureStackTrace(this, ParserError);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a ParserError from a WASM error object
|
|
16
|
+
*/
|
|
17
|
+
static fromWasmError(error) {
|
|
18
|
+
if (typeof error === 'string') {
|
|
19
|
+
return new ParserError(error);
|
|
20
|
+
}
|
|
21
|
+
if (error && typeof error === 'object') {
|
|
22
|
+
const err = error;
|
|
23
|
+
const message = typeof err.message === 'string' ? err.message : String(error);
|
|
24
|
+
const location = typeof err.line === 'number' && typeof err.column === 'number'
|
|
25
|
+
? { line: err.line, column: err.column }
|
|
26
|
+
: undefined;
|
|
27
|
+
return new ParserError(message, location);
|
|
28
|
+
}
|
|
29
|
+
return new ParserError(String(error));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Error thrown when WASM module fails to initialize
|
|
34
|
+
*/
|
|
35
|
+
export class WasmInitError extends Error {
|
|
36
|
+
constructor(message) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = 'WasmInitError';
|
|
39
|
+
if (Error.captureStackTrace) {
|
|
40
|
+
Error.captureStackTrace(this, WasmInitError);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/types/errors.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,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AAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAE5B,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL Dialects
|
|
3
|
+
*
|
|
4
|
+
* Each dialect class represents a specific SQL dialect supported by the parser.
|
|
5
|
+
* These are thin wrappers that provide type safety and a clean API.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base interface for all dialects
|
|
9
|
+
*/
|
|
10
|
+
export interface Dialect {
|
|
11
|
+
/** The name of the dialect as recognized by the WASM module */
|
|
12
|
+
readonly name: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generic SQL dialect - accepts most SQL syntax
|
|
16
|
+
*/
|
|
17
|
+
export declare class GenericDialect implements Dialect {
|
|
18
|
+
readonly name = "generic";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* ANSI SQL standard dialect
|
|
22
|
+
*/
|
|
23
|
+
export declare class AnsiDialect implements Dialect {
|
|
24
|
+
readonly name = "ansi";
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* MySQL dialect
|
|
28
|
+
*/
|
|
29
|
+
export declare class MySqlDialect implements Dialect {
|
|
30
|
+
readonly name = "mysql";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* PostgreSQL dialect
|
|
34
|
+
*/
|
|
35
|
+
export declare class PostgreSqlDialect implements Dialect {
|
|
36
|
+
readonly name = "postgresql";
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* SQLite dialect
|
|
40
|
+
*/
|
|
41
|
+
export declare class SQLiteDialect implements Dialect {
|
|
42
|
+
readonly name = "sqlite";
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Snowflake dialect
|
|
46
|
+
*/
|
|
47
|
+
export declare class SnowflakeDialect implements Dialect {
|
|
48
|
+
readonly name = "snowflake";
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Amazon Redshift dialect
|
|
52
|
+
*/
|
|
53
|
+
export declare class RedshiftDialect implements Dialect {
|
|
54
|
+
readonly name = "redshift";
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Microsoft SQL Server dialect
|
|
58
|
+
*/
|
|
59
|
+
export declare class MsSqlDialect implements Dialect {
|
|
60
|
+
readonly name = "mssql";
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* ClickHouse dialect
|
|
64
|
+
*/
|
|
65
|
+
export declare class ClickHouseDialect implements Dialect {
|
|
66
|
+
readonly name = "clickhouse";
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Google BigQuery dialect
|
|
70
|
+
*/
|
|
71
|
+
export declare class BigQueryDialect implements Dialect {
|
|
72
|
+
readonly name = "bigquery";
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* DuckDB dialect
|
|
76
|
+
*/
|
|
77
|
+
export declare class DuckDbDialect implements Dialect {
|
|
78
|
+
readonly name = "duckdb";
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Databricks dialect
|
|
82
|
+
*/
|
|
83
|
+
export declare class DatabricksDialect implements Dialect {
|
|
84
|
+
readonly name = "databricks";
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Apache Hive dialect
|
|
88
|
+
*/
|
|
89
|
+
export declare class HiveDialect implements Dialect {
|
|
90
|
+
readonly name = "hive";
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* All supported dialect names
|
|
94
|
+
*/
|
|
95
|
+
export declare const SUPPORTED_DIALECTS: readonly ["generic", "ansi", "mysql", "postgresql", "sqlite", "snowflake", "redshift", "mssql", "clickhouse", "bigquery", "duckdb", "databricks", "hive"];
|
|
96
|
+
export type DialectName = (typeof SUPPORTED_DIALECTS)[number];
|
|
97
|
+
/**
|
|
98
|
+
* Create a dialect instance from a string name
|
|
99
|
+
*
|
|
100
|
+
* @param name - The name of the dialect (case-insensitive)
|
|
101
|
+
* @returns A dialect instance, or undefined if the dialect is not recognized
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const dialect = dialectFromString('postgresql');
|
|
106
|
+
* if (dialect) {
|
|
107
|
+
* const ast = Parser.parse('SELECT 1', dialect);
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function dialectFromString(name: string): Dialect | undefined;
|
|
112
|
+
//# sourceMappingURL=dialects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialects.d.ts","sourceRoot":"","sources":["../../src/dialects.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,cAAe,YAAW,OAAO;IAC5C,QAAQ,CAAC,IAAI,aAAa;CAC3B;AAED;;GAEG;AACH,qBAAa,WAAY,YAAW,OAAO;IACzC,QAAQ,CAAC,IAAI,UAAU;CACxB;AAED;;GAEG;AACH,qBAAa,YAAa,YAAW,OAAO;IAC1C,QAAQ,CAAC,IAAI,WAAW;CACzB;AAED;;GAEG;AACH,qBAAa,iBAAkB,YAAW,OAAO;IAC/C,QAAQ,CAAC,IAAI,gBAAgB;CAC9B;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,QAAQ,CAAC,IAAI,YAAY;CAC1B;AAED;;GAEG;AACH,qBAAa,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