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,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SQL Dialects
|
|
4
|
+
*
|
|
5
|
+
* Each dialect class represents a specific SQL dialect supported by the parser.
|
|
6
|
+
* These are thin wrappers that provide type safety and a clean API.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SUPPORTED_DIALECTS = exports.HiveDialect = exports.DatabricksDialect = exports.DuckDbDialect = exports.BigQueryDialect = exports.ClickHouseDialect = exports.MsSqlDialect = exports.RedshiftDialect = exports.SnowflakeDialect = exports.SQLiteDialect = exports.PostgreSqlDialect = exports.MySqlDialect = exports.AnsiDialect = exports.GenericDialect = void 0;
|
|
10
|
+
exports.dialectFromString = dialectFromString;
|
|
11
|
+
/**
|
|
12
|
+
* Generic SQL dialect - accepts most SQL syntax
|
|
13
|
+
*/
|
|
14
|
+
class GenericDialect {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.name = 'generic';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.GenericDialect = GenericDialect;
|
|
20
|
+
/**
|
|
21
|
+
* ANSI SQL standard dialect
|
|
22
|
+
*/
|
|
23
|
+
class AnsiDialect {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.name = 'ansi';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.AnsiDialect = AnsiDialect;
|
|
29
|
+
/**
|
|
30
|
+
* MySQL dialect
|
|
31
|
+
*/
|
|
32
|
+
class MySqlDialect {
|
|
33
|
+
constructor() {
|
|
34
|
+
this.name = 'mysql';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.MySqlDialect = MySqlDialect;
|
|
38
|
+
/**
|
|
39
|
+
* PostgreSQL dialect
|
|
40
|
+
*/
|
|
41
|
+
class PostgreSqlDialect {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.name = 'postgresql';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.PostgreSqlDialect = PostgreSqlDialect;
|
|
47
|
+
/**
|
|
48
|
+
* SQLite dialect
|
|
49
|
+
*/
|
|
50
|
+
class SQLiteDialect {
|
|
51
|
+
constructor() {
|
|
52
|
+
this.name = 'sqlite';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.SQLiteDialect = SQLiteDialect;
|
|
56
|
+
/**
|
|
57
|
+
* Snowflake dialect
|
|
58
|
+
*/
|
|
59
|
+
class SnowflakeDialect {
|
|
60
|
+
constructor() {
|
|
61
|
+
this.name = 'snowflake';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.SnowflakeDialect = SnowflakeDialect;
|
|
65
|
+
/**
|
|
66
|
+
* Amazon Redshift dialect
|
|
67
|
+
*/
|
|
68
|
+
class RedshiftDialect {
|
|
69
|
+
constructor() {
|
|
70
|
+
this.name = 'redshift';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.RedshiftDialect = RedshiftDialect;
|
|
74
|
+
/**
|
|
75
|
+
* Microsoft SQL Server dialect
|
|
76
|
+
*/
|
|
77
|
+
class MsSqlDialect {
|
|
78
|
+
constructor() {
|
|
79
|
+
this.name = 'mssql';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.MsSqlDialect = MsSqlDialect;
|
|
83
|
+
/**
|
|
84
|
+
* ClickHouse dialect
|
|
85
|
+
*/
|
|
86
|
+
class ClickHouseDialect {
|
|
87
|
+
constructor() {
|
|
88
|
+
this.name = 'clickhouse';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.ClickHouseDialect = ClickHouseDialect;
|
|
92
|
+
/**
|
|
93
|
+
* Google BigQuery dialect
|
|
94
|
+
*/
|
|
95
|
+
class BigQueryDialect {
|
|
96
|
+
constructor() {
|
|
97
|
+
this.name = 'bigquery';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.BigQueryDialect = BigQueryDialect;
|
|
101
|
+
/**
|
|
102
|
+
* DuckDB dialect
|
|
103
|
+
*/
|
|
104
|
+
class DuckDbDialect {
|
|
105
|
+
constructor() {
|
|
106
|
+
this.name = 'duckdb';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.DuckDbDialect = DuckDbDialect;
|
|
110
|
+
/**
|
|
111
|
+
* Databricks dialect
|
|
112
|
+
*/
|
|
113
|
+
class DatabricksDialect {
|
|
114
|
+
constructor() {
|
|
115
|
+
this.name = 'databricks';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.DatabricksDialect = DatabricksDialect;
|
|
119
|
+
/**
|
|
120
|
+
* Apache Hive dialect
|
|
121
|
+
*/
|
|
122
|
+
class HiveDialect {
|
|
123
|
+
constructor() {
|
|
124
|
+
this.name = 'hive';
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.HiveDialect = HiveDialect;
|
|
128
|
+
/**
|
|
129
|
+
* All supported dialect names
|
|
130
|
+
*/
|
|
131
|
+
exports.SUPPORTED_DIALECTS = [
|
|
132
|
+
'generic',
|
|
133
|
+
'ansi',
|
|
134
|
+
'mysql',
|
|
135
|
+
'postgresql',
|
|
136
|
+
'sqlite',
|
|
137
|
+
'snowflake',
|
|
138
|
+
'redshift',
|
|
139
|
+
'mssql',
|
|
140
|
+
'clickhouse',
|
|
141
|
+
'bigquery',
|
|
142
|
+
'duckdb',
|
|
143
|
+
'databricks',
|
|
144
|
+
'hive',
|
|
145
|
+
];
|
|
146
|
+
/**
|
|
147
|
+
* Map of dialect names to dialect classes
|
|
148
|
+
*/
|
|
149
|
+
const DIALECT_MAP = {
|
|
150
|
+
generic: GenericDialect,
|
|
151
|
+
ansi: AnsiDialect,
|
|
152
|
+
mysql: MySqlDialect,
|
|
153
|
+
postgresql: PostgreSqlDialect,
|
|
154
|
+
sqlite: SQLiteDialect,
|
|
155
|
+
snowflake: SnowflakeDialect,
|
|
156
|
+
redshift: RedshiftDialect,
|
|
157
|
+
mssql: MsSqlDialect,
|
|
158
|
+
clickhouse: ClickHouseDialect,
|
|
159
|
+
bigquery: BigQueryDialect,
|
|
160
|
+
duckdb: DuckDbDialect,
|
|
161
|
+
databricks: DatabricksDialect,
|
|
162
|
+
hive: HiveDialect,
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Create a dialect instance from a string name
|
|
166
|
+
*
|
|
167
|
+
* @param name - The name of the dialect (case-insensitive)
|
|
168
|
+
* @returns A dialect instance, or undefined if the dialect is not recognized
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const dialect = dialectFromString('postgresql');
|
|
173
|
+
* if (dialect) {
|
|
174
|
+
* const ast = Parser.parse('SELECT 1', dialect);
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
function dialectFromString(name) {
|
|
179
|
+
const normalized = name.toLowerCase();
|
|
180
|
+
// Handle common aliases
|
|
181
|
+
const aliasMap = {
|
|
182
|
+
postgres: 'postgresql',
|
|
183
|
+
pg: 'postgresql',
|
|
184
|
+
sqlserver: 'mssql',
|
|
185
|
+
duck: 'duckdb',
|
|
186
|
+
};
|
|
187
|
+
const dialectName = aliasMap[normalized] ?? normalized;
|
|
188
|
+
const DialectClass = DIALECT_MAP[dialectName];
|
|
189
|
+
return DialectClass ? new DialectClass() : undefined;
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=dialects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialects.js","sourceRoot":"","sources":["../../src/dialects.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA2JH,8CAeC;AAhKD;;GAEG;AACH,MAAa,cAAc;IAA3B;QACW,SAAI,GAAG,SAAS,CAAC;IAC5B,CAAC;CAAA;AAFD,wCAEC;AAED;;GAEG;AACH,MAAa,WAAW;IAAxB;QACW,SAAI,GAAG,MAAM,CAAC;IACzB,CAAC;CAAA;AAFD,kCAEC;AAED;;GAEG;AACH,MAAa,YAAY;IAAzB;QACW,SAAI,GAAG,OAAO,CAAC;IAC1B,CAAC;CAAA;AAFD,oCAEC;AAED;;GAEG;AACH,MAAa,iBAAiB;IAA9B;QACW,SAAI,GAAG,YAAY,CAAC;IA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U,EAAE,iBAAiB;IAC7B,MAAM,EAAE,aAAa;IACrB,SAAS,EAAE,gBAAgB;IAC3B,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,YAAY;IACnB,UAAU,EAAE,iBAAiB;IAC7B,QAAQ,EAAE,eAAe;IACzB,MAAM,EAAE,aAAa;IACrB,UAAU,EAAE,iBAAiB;IAC7B,IAAI,EAAE,WAAW;CAClB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAiB,CAAC;IAErD,wBAAwB;IACxB,MAAM,QAAQ,GAAgC;QAC5C,QAAQ,EAAE,YAAY;QACtB,EAAE,EAAE,YAAY;QAChB,SAAS,EAAE,OAAO;QAClB,IAAI,EAAE,QAAQ;KACf,CAAC;IAEF,MAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC;IACvD,MAAM,YAAY,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;IAE9C,OAAO,YAAY,CAAC,CAAC,CAAC,IAAI,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* sqlparser-rs - SQL Parser for JavaScript/TypeScript
|
|
4
|
+
*
|
|
5
|
+
* This package wraps the Rust sqlparser crate via WebAssembly, providing
|
|
6
|
+
* a fast and accurate SQL parser for JavaScript and TypeScript.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { Parser, GenericDialect, PostgreSqlDialect } from 'sqlparser-rs';
|
|
11
|
+
*
|
|
12
|
+
* // Simple parsing
|
|
13
|
+
* const statements = await Parser.parse('SELECT * FROM users', new GenericDialect());
|
|
14
|
+
*
|
|
15
|
+
* // With specific dialect
|
|
16
|
+
* const pgStatements = await Parser.parse(
|
|
17
|
+
* 'SELECT * FROM users WHERE id = $1',
|
|
18
|
+
* new PostgreSqlDialect()
|
|
19
|
+
* );
|
|
20
|
+
*
|
|
21
|
+
* // Builder pattern with options
|
|
22
|
+
* const parser = new Parser(new PostgreSqlDialect())
|
|
23
|
+
* .withRecursionLimit(50)
|
|
24
|
+
* .withOptions({ trailingCommas: true });
|
|
25
|
+
*
|
|
26
|
+
* const ast = await parser.parseAsync('SELECT * FROM users');
|
|
27
|
+
*
|
|
28
|
+
* // Format SQL
|
|
29
|
+
* const formatted = await Parser.format('select * from users', new GenericDialect());
|
|
30
|
+
* // Returns: "SELECT * FROM users"
|
|
31
|
+
*
|
|
32
|
+
* // Validate SQL
|
|
33
|
+
* try {
|
|
34
|
+
* await Parser.validate('SELECT * FRO users', new GenericDialect());
|
|
35
|
+
* } catch (e) {
|
|
36
|
+
* console.log('Invalid SQL:', e.message);
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @packageDocumentation
|
|
41
|
+
*/
|
|
42
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
43
|
+
if (k2 === undefined) k2 = k;
|
|
44
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
45
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
46
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
47
|
+
}
|
|
48
|
+
Object.defineProperty(o, k2, desc);
|
|
49
|
+
}) : (function(o, m, k, k2) {
|
|
50
|
+
if (k2 === undefined) k2 = k;
|
|
51
|
+
o[k2] = m[k];
|
|
52
|
+
}));
|
|
53
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
54
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.SUPPORTED_DIALECTS = exports.dialectFromString = exports.HiveDialect = exports.DatabricksDialect = exports.DuckDbDialect = exports.BigQueryDialect = exports.ClickHouseDialect = exports.MsSqlDialect = exports.RedshiftDialect = exports.SnowflakeDialect = exports.SQLiteDialect = exports.PostgreSqlDialect = exports.MySqlDialect = exports.AnsiDialect = exports.GenericDialect = exports.initWasm = exports.Parser = void 0;
|
|
58
|
+
// Parser
|
|
59
|
+
var parser_1 = require("./parser");
|
|
60
|
+
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_1.Parser; } });
|
|
61
|
+
Object.defineProperty(exports, "initWasm", { enumerable: true, get: function () { return parser_1.initWasm; } });
|
|
62
|
+
// Dialects
|
|
63
|
+
var dialects_1 = require("./dialects");
|
|
64
|
+
Object.defineProperty(exports, "GenericDialect", { enumerable: true, get: function () { return dialects_1.GenericDialect; } });
|
|
65
|
+
Object.defineProperty(exports, "AnsiDialect", { enumerable: true, get: function () { return dialects_1.AnsiDialect; } });
|
|
66
|
+
Object.defineProperty(exports, "MySqlDialect", { enumerable: true, get: function () { return dialects_1.MySqlDialect; } });
|
|
67
|
+
Object.defineProperty(exports, "PostgreSqlDialect", { enumerable: true, get: function () { return dialects_1.PostgreSqlDialect; } });
|
|
68
|
+
Object.defineProperty(exports, "SQLiteDialect", { enumerable: true, get: function () { return dialects_1.SQLiteDialect; } });
|
|
69
|
+
Object.defineProperty(exports, "SnowflakeDialect", { enumerable: true, get: function () { return dialects_1.SnowflakeDialect; } });
|
|
70
|
+
Object.defineProperty(exports, "RedshiftDialect", { enumerable: true, get: function () { return dialects_1.RedshiftDialect; } });
|
|
71
|
+
Object.defineProperty(exports, "MsSqlDialect", { enumerable: true, get: function () { return dialects_1.MsSqlDialect; } });
|
|
72
|
+
Object.defineProperty(exports, "ClickHouseDialect", { enumerable: true, get: function () { return dialects_1.ClickHouseDialect; } });
|
|
73
|
+
Object.defineProperty(exports, "BigQueryDialect", { enumerable: true, get: function () { return dialects_1.BigQueryDialect; } });
|
|
74
|
+
Object.defineProperty(exports, "DuckDbDialect", { enumerable: true, get: function () { return dialects_1.DuckDbDialect; } });
|
|
75
|
+
Object.defineProperty(exports, "DatabricksDialect", { enumerable: true, get: function () { return dialects_1.DatabricksDialect; } });
|
|
76
|
+
Object.defineProperty(exports, "HiveDialect", { enumerable: true, get: function () { return dialects_1.HiveDialect; } });
|
|
77
|
+
Object.defineProperty(exports, "dialectFromString", { enumerable: true, get: function () { return dialects_1.dialectFromString; } });
|
|
78
|
+
Object.defineProperty(exports, "SUPPORTED_DIALECTS", { enumerable: true, get: function () { return dialects_1.SUPPORTED_DIALECTS; } });
|
|
79
|
+
// Types
|
|
80
|
+
__exportStar(require("./types"), exports);
|
|
81
|
+
//# 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,mCAA4C;AAAnC,gGAAA,MAAM,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAGzB,WAAW;AACX,uCAgBoB;AAflB,0GAAA,cAAc,OAAA;AACd,uGAAA,WAAW,OAAA;AACX,wGAAA,YAAY,OAAA;AACZ,6GAAA,iBAAiB,OAAA;AACjB,yGAAA,aAAa,OAAA;AACb,4GAAA,gBAAgB,OAAA;AAChB,2GAAA,eAAe,OAAA;AACf,wGAAA,YAAY,OAAA;AACZ,6GAAA,iBAAiB,OAAA;AACjB,2GAAA,eAAe,OAAA;AACf,yGAAA,aAAa,OAAA;AACb,6GAAA,iBAAiB,OAAA;AACjB,uGAAA,WAAW,OAAA;AACX,6GAAA,iBAAiB,OAAA;AACjB,8GAAA,kBAAkB,OAAA;AAIpB,QAAQ;AACR,0CAAwB"}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Parser = void 0;
|
|
37
|
+
exports.initWasm = initWasm;
|
|
38
|
+
const dialects_1 = require("./dialects");
|
|
39
|
+
const errors_1 = require("./types/errors");
|
|
40
|
+
// Global WASM module instance
|
|
41
|
+
let wasmModule = null;
|
|
42
|
+
let wasmInitPromise = null;
|
|
43
|
+
/**
|
|
44
|
+
* Initialize the WASM module
|
|
45
|
+
* This is called automatically when needed, but can be called manually for eager loading
|
|
46
|
+
*/
|
|
47
|
+
async function initWasm() {
|
|
48
|
+
await getWasmModule();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get or initialize the WASM module
|
|
52
|
+
*/
|
|
53
|
+
async function getWasmModule() {
|
|
54
|
+
if (wasmModule) {
|
|
55
|
+
return wasmModule;
|
|
56
|
+
}
|
|
57
|
+
if (wasmInitPromise) {
|
|
58
|
+
return wasmInitPromise;
|
|
59
|
+
}
|
|
60
|
+
wasmInitPromise = (async () => {
|
|
61
|
+
try {
|
|
62
|
+
// Try to load the WASM module
|
|
63
|
+
// Use dynamic path to avoid TypeScript path resolution issues
|
|
64
|
+
// The path is relative to the compiled output in dist/cjs or dist/esm
|
|
65
|
+
const wasmPath = '../../wasm/sqlparser_rs_wasm.js';
|
|
66
|
+
const wasm = await Promise.resolve(`${wasmPath}`).then(s => __importStar(require(s)));
|
|
67
|
+
wasmModule = wasm;
|
|
68
|
+
return wasmModule;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new errors_1.WasmInitError(`Failed to initialize WASM module: ${error instanceof Error ? error.message : String(error)}`);
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
74
|
+
return wasmInitPromise;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the WASM module synchronously (throws if not initialized)
|
|
78
|
+
*/
|
|
79
|
+
function getWasmModuleSync() {
|
|
80
|
+
if (!wasmModule) {
|
|
81
|
+
throw new errors_1.WasmInitError('WASM module not initialized. Call initWasm() first or use async methods.');
|
|
82
|
+
}
|
|
83
|
+
return wasmModule;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* SQL Parser
|
|
87
|
+
*
|
|
88
|
+
* Parses SQL statements into an Abstract Syntax Tree (AST).
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* import { Parser, PostgreSqlDialect } from 'sqlparser-rs';
|
|
93
|
+
*
|
|
94
|
+
* // Simple parsing
|
|
95
|
+
* const statements = await Parser.parse('SELECT * FROM users', new PostgreSqlDialect());
|
|
96
|
+
*
|
|
97
|
+
* // With builder pattern
|
|
98
|
+
* const parser = new Parser(new PostgreSqlDialect())
|
|
99
|
+
* .withRecursionLimit(50)
|
|
100
|
+
* .withOptions({ trailingCommas: true });
|
|
101
|
+
*
|
|
102
|
+
* const ast = await parser.parseAsync('SELECT * FROM users');
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
class Parser {
|
|
106
|
+
/**
|
|
107
|
+
* Create a new parser instance
|
|
108
|
+
*
|
|
109
|
+
* @param dialect - The SQL dialect to use (defaults to GenericDialect)
|
|
110
|
+
*/
|
|
111
|
+
constructor(dialect = new dialects_1.GenericDialect()) {
|
|
112
|
+
this.dialect = dialect;
|
|
113
|
+
this.options = {};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Set the recursion limit for parsing nested expressions
|
|
117
|
+
*
|
|
118
|
+
* @param limit - Maximum recursion depth
|
|
119
|
+
* @returns This parser instance for chaining
|
|
120
|
+
*/
|
|
121
|
+
withRecursionLimit(limit) {
|
|
122
|
+
this.options.recursionLimit = limit;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Set parser options
|
|
127
|
+
*
|
|
128
|
+
* @param options - Parser options
|
|
129
|
+
* @returns This parser instance for chaining
|
|
130
|
+
*/
|
|
131
|
+
withOptions(options) {
|
|
132
|
+
this.options = { ...this.options, ...options };
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Parse SQL statements asynchronously
|
|
137
|
+
*
|
|
138
|
+
* @param sql - SQL string to parse
|
|
139
|
+
* @returns Array of parsed statements
|
|
140
|
+
*/
|
|
141
|
+
async parseAsync(sql) {
|
|
142
|
+
const wasm = await getWasmModule();
|
|
143
|
+
return this.parseWithWasm(wasm, sql);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Parse SQL statements synchronously
|
|
147
|
+
* Requires WASM module to be initialized first via initWasm()
|
|
148
|
+
*
|
|
149
|
+
* @param sql - SQL string to parse
|
|
150
|
+
* @returns Array of parsed statements
|
|
151
|
+
*/
|
|
152
|
+
parseSync(sql) {
|
|
153
|
+
const wasm = getWasmModuleSync();
|
|
154
|
+
return this.parseWithWasm(wasm, sql);
|
|
155
|
+
}
|
|
156
|
+
parseWithWasm(wasm, sql) {
|
|
157
|
+
try {
|
|
158
|
+
const hasOptions = Object.keys(this.options).length > 0;
|
|
159
|
+
if (hasOptions) {
|
|
160
|
+
const result = wasm.parse_sql_with_options(this.dialect.name, sql, this.options);
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
const result = wasm.parse_sql(this.dialect.name, sql);
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
throw errors_1.ParserError.fromWasmError(error);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// ============================================================================
|
|
173
|
+
// Static methods for simple one-off parsing
|
|
174
|
+
// ============================================================================
|
|
175
|
+
/**
|
|
176
|
+
* Parse SQL statements (async)
|
|
177
|
+
*
|
|
178
|
+
* @param sql - SQL string to parse
|
|
179
|
+
* @param dialect - SQL dialect to use
|
|
180
|
+
* @returns Array of parsed statements
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* const statements = await Parser.parse('SELECT 1', new GenericDialect());
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
static async parse(sql, dialect = new dialects_1.GenericDialect()) {
|
|
188
|
+
const parser = new Parser(dialect);
|
|
189
|
+
return parser.parseAsync(sql);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Parse SQL and return the AST as a JSON string (async)
|
|
193
|
+
*
|
|
194
|
+
* @param sql - SQL string to parse
|
|
195
|
+
* @param dialect - SQL dialect to use
|
|
196
|
+
* @returns JSON string representation of the AST
|
|
197
|
+
*/
|
|
198
|
+
static async parseToJson(sql, dialect = new dialects_1.GenericDialect()) {
|
|
199
|
+
const wasm = await getWasmModule();
|
|
200
|
+
try {
|
|
201
|
+
return wasm.parse_sql_to_json_string(dialect.name, sql);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
throw errors_1.ParserError.fromWasmError(error);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Parse SQL and return a formatted string representation (async)
|
|
209
|
+
*
|
|
210
|
+
* @param sql - SQL string to parse
|
|
211
|
+
* @param dialect - SQL dialect to use
|
|
212
|
+
* @returns String representation of the parsed SQL
|
|
213
|
+
*/
|
|
214
|
+
static async parseToString(sql, dialect = new dialects_1.GenericDialect()) {
|
|
215
|
+
const wasm = await getWasmModule();
|
|
216
|
+
try {
|
|
217
|
+
return wasm.parse_sql_to_string(dialect.name, sql);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
throw errors_1.ParserError.fromWasmError(error);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Format SQL by parsing and regenerating it (round-trip)
|
|
225
|
+
*
|
|
226
|
+
* @param sql - SQL string to format
|
|
227
|
+
* @param dialect - SQL dialect to use
|
|
228
|
+
* @returns Formatted SQL string
|
|
229
|
+
*/
|
|
230
|
+
static async format(sql, dialect = new dialects_1.GenericDialect()) {
|
|
231
|
+
const wasm = await getWasmModule();
|
|
232
|
+
try {
|
|
233
|
+
return wasm.format_sql(dialect.name, sql);
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
throw errors_1.ParserError.fromWasmError(error);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Validate SQL syntax without returning the full AST
|
|
241
|
+
*
|
|
242
|
+
* @param sql - SQL string to validate
|
|
243
|
+
* @param dialect - SQL dialect to use
|
|
244
|
+
* @returns true if valid, throws ParserError if invalid
|
|
245
|
+
*/
|
|
246
|
+
static async validate(sql, dialect = new dialects_1.GenericDialect()) {
|
|
247
|
+
const wasm = await getWasmModule();
|
|
248
|
+
try {
|
|
249
|
+
return wasm.validate_sql(dialect.name, sql);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
throw errors_1.ParserError.fromWasmError(error);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Get the list of supported dialect names
|
|
257
|
+
*/
|
|
258
|
+
static async getSupportedDialects() {
|
|
259
|
+
const wasm = await getWasmModule();
|
|
260
|
+
return wasm.get_supported_dialects();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.Parser = Parser;
|
|
264
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,4BAEC;AAxCD,yCAA4C;AAC5C,2CAA4D;AA6B5D,8BAA8B;AAC9B,IAAI,UAAU,GAAsB,IAAI,CAAC;AACzC,IAAI,eAAe,GAA+B,IAAI,CAAC;AAEvD;;;GAGG;AACI,KAAK,UAAU,QAAQ;IAC5B,MAAM,aAAa,EAAE,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,aAAa;IAC1B,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,eAAe,EAAE,CAAC;QACpB,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,eAAe,GAAG,CAAC,KAAK,IAAI,EAAE;QAC5B,IAAI,CAAC;YACH,8BAA8B;YA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;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,oBAAW,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;AA3KD,wBA2KC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TypeScript type definitions for sqlparser-rs AST
|
|
4
|
+
*
|
|
5
|
+
* These types mirror the Rust AST structure from the sqlparser crate.
|
|
6
|
+
* The AST is serialized as JSON from Rust, so these types represent
|
|
7
|
+
* the JSON structure.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
//# 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,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WasmInitError = exports.ParserError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when SQL parsing fails
|
|
6
|
+
*/
|
|
7
|
+
class ParserError extends Error {
|
|
8
|
+
constructor(message, location) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'ParserError';
|
|
11
|
+
this.location = location;
|
|
12
|
+
// Maintain proper stack trace in V8 environments
|
|
13
|
+
if (Error.captureStackTrace) {
|
|
14
|
+
Error.captureStackTrace(this, ParserError);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a ParserError from a WASM error object
|
|
19
|
+
*/
|
|
20
|
+
static fromWasmError(error) {
|
|
21
|
+
if (typeof error === 'string') {
|
|
22
|
+
return new ParserError(error);
|
|
23
|
+
}
|
|
24
|
+
if (error && typeof error === 'object') {
|
|
25
|
+
const err = error;
|
|
26
|
+
const message = typeof err.message === 'string' ? err.message : String(error);
|
|
27
|
+
const location = typeof err.line === 'number' && typeof err.column === 'number'
|
|
28
|
+
? { line: err.line, column: err.column }
|
|
29
|
+
: undefined;
|
|
30
|
+
return new ParserError(message, location);
|
|
31
|
+
}
|
|
32
|
+
return new ParserError(String(error));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ParserError = ParserError;
|
|
36
|
+
/**
|
|
37
|
+
* Error thrown when WASM module fails to initialize
|
|
38
|
+
*/
|
|
39
|
+
class WasmInitError extends Error {
|
|
40
|
+
constructor(message) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.name = 'WasmInitError';
|
|
43
|
+
if (Error.captureStackTrace) {
|
|
44
|
+
Error.captureStackTrace(this, WasmInitError);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.WasmInitError = WasmInitError;
|
|
49
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/types/errors.ts"],"names":[],"mappings":";;;AAQA;;GAEG;AACH,MAAa,WAAY,SAAQ,KAAK;IAGpC,YAAY,OAAe,EAAE,QAAwB;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,iDAAiD;QACjD,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,KAAc;QACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;QAED,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvC,MAAM,GAAG,GAAG,KAAgC,CAAC;YAC7C,MAAM,OAAO,GAAG,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9E,MAAM,QAAQ,GACZ,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ;gBAC5D,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE;gBACxC,CAAC,CAAC,SAAS,CAAC;YAChB,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACxC,CAAC;CACF;AAlCD,kCAkCC;AAED;;GAEG;AACH,MAAa,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,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;AATD,sCASC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ast"), exports);
|
|
18
|
+
__exportStar(require("./errors"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,2CAAyB"}
|