sqlparser-rs 0.60.2 → 0.60.3

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.
Files changed (46) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs +402 -0
  3. package/dist/index.d.cts +1359 -0
  4. package/dist/index.d.mts +1359 -0
  5. package/dist/index.mjs +384 -0
  6. package/package.json +10 -10
  7. package/wasm/README.md +1 -1
  8. package/wasm/package.json +1 -1
  9. package/wasm/sqlparser_rs_wasm_bg.wasm +0 -0
  10. package/dist/cjs/dialects.js +0 -202
  11. package/dist/cjs/dialects.js.map +0 -1
  12. package/dist/cjs/index.js +0 -81
  13. package/dist/cjs/index.js.map +0 -1
  14. package/dist/cjs/parser.js +0 -191
  15. package/dist/cjs/parser.js.map +0 -1
  16. package/dist/cjs/types/ast.js +0 -10
  17. package/dist/cjs/types/ast.js.map +0 -1
  18. package/dist/cjs/types/errors.js +0 -49
  19. package/dist/cjs/types/errors.js.map +0 -1
  20. package/dist/cjs/types/index.js +0 -19
  21. package/dist/cjs/types/index.js.map +0 -1
  22. package/dist/esm/dialects.js +0 -184
  23. package/dist/esm/dialects.js.map +0 -1
  24. package/dist/esm/index.js +0 -47
  25. package/dist/esm/index.js.map +0 -1
  26. package/dist/esm/package.json +0 -1
  27. package/dist/esm/parser.js +0 -187
  28. package/dist/esm/parser.js.map +0 -1
  29. package/dist/esm/types/ast.js +0 -9
  30. package/dist/esm/types/ast.js.map +0 -1
  31. package/dist/esm/types/errors.js +0 -44
  32. package/dist/esm/types/errors.js.map +0 -1
  33. package/dist/esm/types/index.js +0 -3
  34. package/dist/esm/types/index.js.map +0 -1
  35. package/dist/types/dialects.d.ts +0 -118
  36. package/dist/types/dialects.d.ts.map +0 -1
  37. package/dist/types/index.d.ts +0 -46
  38. package/dist/types/index.d.ts.map +0 -1
  39. package/dist/types/parser.d.ts +0 -116
  40. package/dist/types/parser.d.ts.map +0 -1
  41. package/dist/types/types/ast.d.ts +0 -1097
  42. package/dist/types/types/ast.d.ts.map +0 -1
  43. package/dist/types/types/errors.d.ts +0 -25
  44. package/dist/types/types/errors.d.ts.map +0 -1
  45. package/dist/types/types/index.d.ts +0 -3
  46. package/dist/types/types/index.d.ts.map +0 -1
package/dist/cjs/index.js DELETED
@@ -1,81 +0,0 @@
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 = Parser.parse('SELECT * FROM users', new GenericDialect());
14
- *
15
- * // With specific dialect
16
- * const pgStatements = 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 = parser.parse('SELECT * FROM users');
27
- *
28
- * // Format SQL
29
- * const formatted = Parser.format('select * from users', new GenericDialect());
30
- * // Returns: "SELECT * FROM users"
31
- *
32
- * // Validate SQL
33
- * try {
34
- * 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.OracleDialect = 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.Parser = void 0;
58
- // Parser
59
- var parser_js_1 = require("./parser.js");
60
- Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_js_1.Parser; } });
61
- // Dialects
62
- var dialects_js_1 = require("./dialects.js");
63
- Object.defineProperty(exports, "GenericDialect", { enumerable: true, get: function () { return dialects_js_1.GenericDialect; } });
64
- Object.defineProperty(exports, "AnsiDialect", { enumerable: true, get: function () { return dialects_js_1.AnsiDialect; } });
65
- Object.defineProperty(exports, "MySqlDialect", { enumerable: true, get: function () { return dialects_js_1.MySqlDialect; } });
66
- Object.defineProperty(exports, "PostgreSqlDialect", { enumerable: true, get: function () { return dialects_js_1.PostgreSqlDialect; } });
67
- Object.defineProperty(exports, "SQLiteDialect", { enumerable: true, get: function () { return dialects_js_1.SQLiteDialect; } });
68
- Object.defineProperty(exports, "SnowflakeDialect", { enumerable: true, get: function () { return dialects_js_1.SnowflakeDialect; } });
69
- Object.defineProperty(exports, "RedshiftDialect", { enumerable: true, get: function () { return dialects_js_1.RedshiftDialect; } });
70
- Object.defineProperty(exports, "MsSqlDialect", { enumerable: true, get: function () { return dialects_js_1.MsSqlDialect; } });
71
- Object.defineProperty(exports, "ClickHouseDialect", { enumerable: true, get: function () { return dialects_js_1.ClickHouseDialect; } });
72
- Object.defineProperty(exports, "BigQueryDialect", { enumerable: true, get: function () { return dialects_js_1.BigQueryDialect; } });
73
- Object.defineProperty(exports, "DuckDbDialect", { enumerable: true, get: function () { return dialects_js_1.DuckDbDialect; } });
74
- Object.defineProperty(exports, "DatabricksDialect", { enumerable: true, get: function () { return dialects_js_1.DatabricksDialect; } });
75
- Object.defineProperty(exports, "HiveDialect", { enumerable: true, get: function () { return dialects_js_1.HiveDialect; } });
76
- Object.defineProperty(exports, "OracleDialect", { enumerable: true, get: function () { return dialects_js_1.OracleDialect; } });
77
- Object.defineProperty(exports, "dialectFromString", { enumerable: true, get: function () { return dialects_js_1.dialectFromString; } });
78
- Object.defineProperty(exports, "SUPPORTED_DIALECTS", { enumerable: true, get: function () { return dialects_js_1.SUPPORTED_DIALECTS; } });
79
- // Types
80
- __exportStar(require("./types/index.js"), exports);
81
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;;;;;;;;;;;;;;;;;AAEH,SAAS;AACT,yCAAqC;AAA5B,mGAAA,MAAM,OAAA;AAGf,WAAW;AACX,6CAiBuB;AAhBrB,6GAAA,cAAc,OAAA;AACd,0GAAA,WAAW,OAAA;AACX,2GAAA,YAAY,OAAA;AACZ,gHAAA,iBAAiB,OAAA;AACjB,4GAAA,aAAa,OAAA;AACb,+GAAA,gBAAgB,OAAA;AAChB,8GAAA,eAAe,OAAA;AACf,2GAAA,YAAY,OAAA;AACZ,gHAAA,iBAAiB,OAAA;AACjB,8GAAA,eAAe,OAAA;AACf,4GAAA,aAAa,OAAA;AACb,gHAAA,iBAAiB,OAAA;AACjB,0GAAA,WAAW,OAAA;AACX,4GAAA,aAAa,OAAA;AACb,gHAAA,iBAAiB,OAAA;AACjB,iHAAA,kBAAkB,OAAA;AAIpB,QAAQ;AACR,mDAAiC"}
@@ -1,191 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Parser = void 0;
4
- const dialects_js_1 = require("./dialects.js");
5
- const errors_js_1 = require("./types/errors.js");
6
- // Lazily loaded WASM module - loaded synchronously on first access
7
- let wasmModule = null;
8
- /**
9
- * Get the WASM module (loads synchronously on first access)
10
- */
11
- function getWasmModule() {
12
- if (wasmModule) {
13
- return wasmModule;
14
- }
15
- try {
16
- // Use require() for synchronous loading
17
- // The path is relative to the compiled output in dist/cjs or dist/esm
18
- // eslint-disable-next-line @typescript-eslint/no-require-imports
19
- wasmModule = require('../../wasm/sqlparser_rs_wasm.js');
20
- return wasmModule;
21
- }
22
- catch (error) {
23
- throw new errors_js_1.WasmInitError(`Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`);
24
- }
25
- }
26
- /**
27
- * SQL Parser
28
- *
29
- * Parses SQL statements into an Abstract Syntax Tree (AST).
30
- *
31
- * @example
32
- * ```typescript
33
- * import { Parser, PostgreSqlDialect } from 'sqlparser-rs';
34
- *
35
- * // Simple parsing
36
- * const statements = Parser.parse('SELECT * FROM users', new PostgreSqlDialect());
37
- *
38
- * // With builder pattern
39
- * const parser = new Parser(new PostgreSqlDialect())
40
- * .withRecursionLimit(50)
41
- * .withOptions({ trailingCommas: true });
42
- *
43
- * const ast = parser.parse('SELECT * FROM users');
44
- * ```
45
- */
46
- class Parser {
47
- /**
48
- * Create a new parser instance
49
- *
50
- * @param dialect - The SQL dialect to use (defaults to GenericDialect)
51
- */
52
- constructor(dialect = new dialects_js_1.GenericDialect()) {
53
- this.dialect = dialect;
54
- this.options = {};
55
- }
56
- /**
57
- * Set the recursion limit for parsing nested expressions
58
- *
59
- * @param limit - Maximum recursion depth
60
- * @returns This parser instance for chaining
61
- */
62
- withRecursionLimit(limit) {
63
- this.options.recursionLimit = limit;
64
- return this;
65
- }
66
- /**
67
- * Set parser options
68
- *
69
- * @param options - Parser options
70
- * @returns This parser instance for chaining
71
- */
72
- withOptions(options) {
73
- this.options = { ...this.options, ...options };
74
- return this;
75
- }
76
- /**
77
- * Parse SQL statements
78
- *
79
- * @param sql - SQL string to parse
80
- * @returns Array of parsed statements
81
- */
82
- parse(sql) {
83
- const wasm = getWasmModule();
84
- try {
85
- const hasOptions = Object.keys(this.options).length > 0;
86
- if (hasOptions) {
87
- const result = wasm.parse_sql_with_options(this.dialect.name, sql, this.options);
88
- return result;
89
- }
90
- else {
91
- const result = wasm.parse_sql(this.dialect.name, sql);
92
- return result;
93
- }
94
- }
95
- catch (error) {
96
- throw errors_js_1.ParserError.fromWasmError(error);
97
- }
98
- }
99
- // ============================================================================
100
- // Static methods for simple one-off parsing
101
- // ============================================================================
102
- /**
103
- * Parse SQL statements
104
- *
105
- * @param sql - SQL string to parse
106
- * @param dialect - SQL dialect to use
107
- * @returns Array of parsed statements
108
- *
109
- * @example
110
- * ```typescript
111
- * const statements = Parser.parse('SELECT 1', new GenericDialect());
112
- * ```
113
- */
114
- static parse(sql, dialect = new dialects_js_1.GenericDialect()) {
115
- const parser = new Parser(dialect);
116
- return parser.parse(sql);
117
- }
118
- /**
119
- * Parse SQL and return the AST as a JSON string
120
- *
121
- * @param sql - SQL string to parse
122
- * @param dialect - SQL dialect to use
123
- * @returns JSON string representation of the AST
124
- */
125
- static parseToJson(sql, dialect = new dialects_js_1.GenericDialect()) {
126
- const wasm = getWasmModule();
127
- try {
128
- return wasm.parse_sql_to_json_string(dialect.name, sql);
129
- }
130
- catch (error) {
131
- throw errors_js_1.ParserError.fromWasmError(error);
132
- }
133
- }
134
- /**
135
- * Parse SQL and return a formatted string representation
136
- *
137
- * @param sql - SQL string to parse
138
- * @param dialect - SQL dialect to use
139
- * @returns String representation of the parsed SQL
140
- */
141
- static parseToString(sql, dialect = new dialects_js_1.GenericDialect()) {
142
- const wasm = getWasmModule();
143
- try {
144
- return wasm.parse_sql_to_string(dialect.name, sql);
145
- }
146
- catch (error) {
147
- throw errors_js_1.ParserError.fromWasmError(error);
148
- }
149
- }
150
- /**
151
- * Format SQL by parsing and regenerating it (round-trip)
152
- *
153
- * @param sql - SQL string to format
154
- * @param dialect - SQL dialect to use
155
- * @returns Formatted SQL string
156
- */
157
- static format(sql, dialect = new dialects_js_1.GenericDialect()) {
158
- const wasm = getWasmModule();
159
- try {
160
- return wasm.format_sql(dialect.name, sql);
161
- }
162
- catch (error) {
163
- throw errors_js_1.ParserError.fromWasmError(error);
164
- }
165
- }
166
- /**
167
- * Validate SQL syntax without returning the full AST
168
- *
169
- * @param sql - SQL string to validate
170
- * @param dialect - SQL dialect to use
171
- * @returns true if valid, throws ParserError if invalid
172
- */
173
- static validate(sql, dialect = new dialects_js_1.GenericDialect()) {
174
- const wasm = getWasmModule();
175
- try {
176
- return wasm.validate_sql(dialect.name, sql);
177
- }
178
- catch (error) {
179
- throw errors_js_1.ParserError.fromWasmError(error);
180
- }
181
- }
182
- /**
183
- * Get the list of supported dialect names
184
- */
185
- static getSupportedDialects() {
186
- const wasm = getWasmModule();
187
- return wasm.get_supported_dialects();
188
- }
189
- }
190
- exports.Parser = Parser;
191
- //# sourceMappingURL=parser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":";;;AACA,+CAA+C;AAC/C,iDAA+D;AA6B/D,mEAAmE;AACnE,IAAI,UAAU,GAAsB,IAAI,CAAC;AAEzC;;GAEG;AACH,SAAS,aAAa;IACpB,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,CAAC;QACH,wCAAwC;QACxC,sEAAsE;QACtE,iEAAiE;QACjE,UAAU,GAAG,OAAO,CAAC,iCAAiC,CAAe,CAAC;QACtE,OAAO,UAAU,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,yBAAa,CACrB,+BAA+B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACxF,CAAC;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QACzC,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,GAAW,EAAE,UAAmB,IAAI,4BAAc,EAAE;QAClE,MAAM,IAAI,GAAG,aAAa,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,uBAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,oBAAoB;QACzB,MAAM,IAAI,GAAG,aAAa,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,sBAAsB,EAAE,CAAC;IACvC,CAAC;CACF;AA3JD,wBA2JC"}
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"ast.js","sourceRoot":"","sources":["../../../src/types/ast.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG"}
@@ -1,49 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,19 +0,0 @@
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.js"), exports);
18
- __exportStar(require("./errors.js"), exports);
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,8CAA4B"}
@@ -1,184 +0,0 @@
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
- * Oracle dialect
113
- */
114
- export class OracleDialect {
115
- constructor() {
116
- this.name = 'oracle';
117
- }
118
- }
119
- /**
120
- * All supported dialect names
121
- */
122
- export const SUPPORTED_DIALECTS = [
123
- 'generic',
124
- 'ansi',
125
- 'mysql',
126
- 'postgresql',
127
- 'sqlite',
128
- 'snowflake',
129
- 'redshift',
130
- 'mssql',
131
- 'clickhouse',
132
- 'bigquery',
133
- 'duckdb',
134
- 'databricks',
135
- 'hive',
136
- 'oracle',
137
- ];
138
- /**
139
- * Map of dialect names to dialect classes
140
- */
141
- const DIALECT_MAP = {
142
- generic: GenericDialect,
143
- ansi: AnsiDialect,
144
- mysql: MySqlDialect,
145
- postgresql: PostgreSqlDialect,
146
- sqlite: SQLiteDialect,
147
- snowflake: SnowflakeDialect,
148
- redshift: RedshiftDialect,
149
- mssql: MsSqlDialect,
150
- clickhouse: ClickHouseDialect,
151
- bigquery: BigQueryDialect,
152
- duckdb: DuckDbDialect,
153
- databricks: DatabricksDialect,
154
- hive: HiveDialect,
155
- oracle: OracleDialect,
156
- };
157
- /**
158
- * Create a dialect instance from a string name
159
- *
160
- * @param name - The name of the dialect (case-insensitive)
161
- * @returns A dialect instance, or undefined if the dialect is not recognized
162
- *
163
- * @example
164
- * ```typescript
165
- * const dialect = dialectFromString('postgresql');
166
- * if (dialect) {
167
- * const ast = Parser.parse('SELECT 1', dialect);
168
- * }
169
- * ```
170
- */
171
- export function dialectFromString(name) {
172
- const normalized = name.toLowerCase();
173
- // Handle common aliases
174
- const aliasMap = {
175
- postgres: 'postgresql',
176
- pg: 'postgresql',
177
- sqlserver: 'mssql',
178
- duck: 'duckdb',
179
- };
180
- const dialectName = aliasMap[normalized] ?? normalized;
181
- const DialectClass = DIALECT_MAP[dialectName];
182
- return DialectClass ? new DialectClass() : undefined;
183
- }
184
- //# sourceMappingURL=dialects.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dialects.js","sourceRoot":"","sources":["../../src/dialects.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH;;GAEG;AACH,MAAM,OAAO,cAAc;IAA3B;QACW,SAAI,GAAG,SAAS,CAAC;IAC5B,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO,WAAW;IAAxB;QACW,SAAI,GAAG,MAAM,CAAC;IACzB,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO,YAAY;IAAzB;QACW,SAAI,GAAG,OAAO,CAAC;IAC1B,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAA9B;QACW,SAAI,GAAG,YAAY,CAAC;IAC/B,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO,aAAa;IAA1B;QACW,SAAI,GAAG,QAAQ,CAAC;IAC3B,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAA7B;QACW,SAAI,GAAG,WAAW,CAAC;IAC9B,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO,eAAe;IAA5B;QACW,SAAI,GAAG,UAAU,CAAC;IAC7B,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO,YAAY;IAAzB;QACW,SAAI,GAAG,OAAO,CAAC;IAC1B,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAA9B;QACW,SAAI,GAAG,YAAY,CAAC;IAC/B,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO,eAAe;IAA5B;QACW,SAAI,GAAG,UAAU,CAAC;IAC7B,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO,aAAa;IAA1B;QACW,SAAI,GAAG,QAAQ,C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AAU,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"}
package/dist/esm/index.js DELETED
@@ -1,47 +0,0 @@
1
- /**
2
- * sqlparser-rs - SQL Parser for JavaScript/TypeScript
3
- *
4
- * This package wraps the Rust sqlparser crate via WebAssembly, 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 = Parser.parse('SELECT * FROM users', new GenericDialect());
13
- *
14
- * // With specific dialect
15
- * const pgStatements = 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 = parser.parse('SELECT * FROM users');
26
- *
27
- * // Format SQL
28
- * const formatted = Parser.format('select * from users', new GenericDialect());
29
- * // Returns: "SELECT * FROM users"
30
- *
31
- * // Validate SQL
32
- * try {
33
- * 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 } from './parser.js';
43
- // Dialects
44
- export { GenericDialect, AnsiDialect, MySqlDialect, PostgreSqlDialect, SQLiteDialect, SnowflakeDialect, RedshiftDialect, MsSqlDialect, ClickHouseDialect, BigQueryDialect, DuckDbDialect, DatabricksDialect, HiveDialect, OracleDialect, dialectFromString, SUPPORTED_DIALECTS, } from './dialects.js';
45
- // Types
46
- export * from './types/index.js';
47
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,SAAS;AACT,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,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,aAAa,EACb,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AAGvB,QAAQ;AACR,cAAc,kBAAkB,CAAC"}
@@ -1 +0,0 @@
1
- {"type":"module"}