sqlparser-rs 0.60.4-rc1 → 0.61.1
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/LICENSE +201 -0
- package/README.md +32 -6
- package/dist/index.cjs +23 -37
- package/dist/index.d.cts +6 -10
- package/dist/index.d.mts +6 -10
- package/dist/index.mjs +22 -36
- package/package.json +9 -11
- package/wasm/README.md +32 -6
- package/wasm/package.json +8 -4
- package/wasm/sqlparser_rs_wasm.d.ts +44 -0
- package/wasm/sqlparser_rs_wasm.js +108 -21
- package/wasm/sqlparser_rs_wasm_bg.wasm +0 -0
- package/wasm/sqlparser_rs_wasm_web.js +0 -628
- package/wasm/sqlparser_rs_wasm_web_bg.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
# sqlparser-
|
|
1
|
+
# sqlparser-ts
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@guanmingchiu/sqlparser-ts)
|
|
4
|
+
[](https://www.npmjs.com/package/@guanmingchiu/sqlparser-ts)
|
|
4
5
|
[](LICENSE)
|
|
5
6
|
[](https://webassembly.org/)
|
|
6
|
-
[](https://github.com/apache/datafusion-sqlparser-rs)
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
SQL parser for JavaScript and TypeScript, powered by [datafusion-sqlparser-rs](https://github.com/apache/datafusion-sqlparser-rs) via WebAssembly.
|
|
9
10
|
|
|
10
11
|
## Features
|
|
11
12
|
|
|
@@ -18,13 +19,16 @@ A SQL parser for JavaScript and TypeScript, powered by [datafusion-sqlparser-rs]
|
|
|
18
19
|
## Installation
|
|
19
20
|
|
|
20
21
|
```bash
|
|
21
|
-
npm install sqlparser-
|
|
22
|
+
npm install @guanmingchiu/sqlparser-ts
|
|
22
23
|
```
|
|
23
24
|
|
|
24
25
|
## Usage
|
|
25
26
|
|
|
26
27
|
```typescript
|
|
27
|
-
import { parse, format, validate } from 'sqlparser-
|
|
28
|
+
import { init, parse, format, validate } from '@guanmingchiu/sqlparser-ts';
|
|
29
|
+
|
|
30
|
+
// Initialize WASM module (must be called once before using any parser functions)
|
|
31
|
+
await init();
|
|
28
32
|
|
|
29
33
|
// Parse SQL into AST
|
|
30
34
|
const ast = parse('SELECT * FROM users');
|
|
@@ -40,6 +44,19 @@ const sql = format('select * from users');
|
|
|
40
44
|
validate('SELECT * FROM users'); // ok
|
|
41
45
|
```
|
|
42
46
|
|
|
47
|
+
### Vite Configuration
|
|
48
|
+
|
|
49
|
+
WASM packages must be excluded from Vite's dev server [dependency pre-bundling](https://github.com/vitejs/vite/discussions/9256). This only affects the dev server. Production builds use Rollup instead of esbuild and handle WASM files correctly.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// vite.config.ts
|
|
53
|
+
export default defineConfig({
|
|
54
|
+
optimizeDeps: {
|
|
55
|
+
exclude: ['@guanmingchiu/sqlparser-ts'],
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
43
60
|
### Working with AST
|
|
44
61
|
|
|
45
62
|
```typescript
|
|
@@ -74,6 +91,15 @@ try {
|
|
|
74
91
|
|
|
75
92
|
`generic`, `ansi`, `mysql`, `postgresql`, `sqlite`, `snowflake`, `redshift`, `mssql`, `clickhouse`, `bigquery`, `duckdb`, `databricks`, `hive`, `oracle`
|
|
76
93
|
|
|
94
|
+
## Versioning
|
|
95
|
+
|
|
96
|
+
Follows [Semantic Versioning](https://semver.org/) with upstream tracking:
|
|
97
|
+
|
|
98
|
+
- MAJOR.MINOR: Tracks upstream [datafusion-sqlparser-rs](https://github.com/apache/datafusion-sqlparser-rs)
|
|
99
|
+
- PATCH: sqlparser-ts specific releases
|
|
100
|
+
|
|
101
|
+
Example: `0.60.4` = upstream 0.60 + 4 sqlparser-ts releases
|
|
102
|
+
|
|
77
103
|
## License
|
|
78
104
|
|
|
79
105
|
Apache-2.0
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1
2
|
|
|
2
3
|
//#region src/dialects.ts
|
|
3
4
|
/**
|
|
@@ -204,55 +205,41 @@ var WasmInitError = class WasmInitError extends Error {
|
|
|
204
205
|
//#region src/wasm.ts
|
|
205
206
|
let wasmModule = null;
|
|
206
207
|
let initPromise = null;
|
|
207
|
-
let initStarted = false;
|
|
208
208
|
const isBrowser = typeof window !== "undefined" && typeof process === "undefined";
|
|
209
|
-
function startInit() {
|
|
210
|
-
if (initStarted) return;
|
|
211
|
-
initStarted = true;
|
|
212
|
-
initPromise = initWasm().catch(() => {});
|
|
213
|
-
}
|
|
214
|
-
startInit();
|
|
215
209
|
/** Get initialized WASM module or throw */
|
|
216
210
|
function getWasmModule() {
|
|
217
211
|
if (wasmModule) return wasmModule;
|
|
218
|
-
throw new WasmInitError("WASM module not yet initialized.
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Wait for WASM module to be ready
|
|
222
|
-
*/
|
|
223
|
-
async function ready() {
|
|
224
|
-
startInit();
|
|
225
|
-
await initPromise;
|
|
212
|
+
throw new WasmInitError("WASM module not yet initialized. Call `await init()` before using the parser.");
|
|
226
213
|
}
|
|
227
214
|
/**
|
|
228
|
-
* Initialize the WASM module
|
|
229
|
-
*
|
|
215
|
+
* Initialize the WASM module. Must be called before using any parser functions.
|
|
216
|
+
* Safe to call multiple times, subsequent calls are no-ops.
|
|
230
217
|
*/
|
|
231
|
-
async function
|
|
218
|
+
async function init() {
|
|
232
219
|
if (wasmModule) return;
|
|
233
|
-
if (
|
|
220
|
+
if (!initPromise) initPromise = (async () => {
|
|
234
221
|
try {
|
|
235
|
-
const wasmJsUrl = new URL("../wasm/sqlparser_rs_wasm_web.js", require("url").pathToFileURL(__filename).href);
|
|
236
|
-
const wasmBinaryUrl = new URL("../wasm/sqlparser_rs_wasm_web_bg.wasm", require("url").pathToFileURL(__filename).href);
|
|
237
222
|
const wasm = await import(
|
|
238
223
|
/* @vite-ignore */
|
|
239
|
-
|
|
224
|
+
"../wasm/sqlparser_rs_wasm.js"
|
|
240
225
|
);
|
|
241
|
-
if (
|
|
226
|
+
if (isBrowser) {
|
|
227
|
+
const wasmUrl = new URL("../wasm/sqlparser_rs_wasm_bg.wasm", require("url").pathToFileURL(__filename).href);
|
|
228
|
+
await wasm.default({ module_or_path: wasmUrl });
|
|
229
|
+
} else {
|
|
230
|
+
const { readFile } = await import(
|
|
231
|
+
/* @vite-ignore */
|
|
232
|
+
"node:fs/promises"
|
|
233
|
+
);
|
|
234
|
+
const bytes = await readFile(new URL("../wasm/sqlparser_rs_wasm_bg.wasm", require("url").pathToFileURL(__filename).href));
|
|
235
|
+
await wasm.default({ module_or_path: bytes });
|
|
236
|
+
}
|
|
242
237
|
wasmModule = wasm;
|
|
243
238
|
} catch (error) {
|
|
244
|
-
throw new WasmInitError(`Failed to load WASM module
|
|
239
|
+
throw new WasmInitError(`Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`);
|
|
245
240
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
try {
|
|
249
|
-
wasmModule = await import(
|
|
250
|
-
/* @vite-ignore */
|
|
251
|
-
new URL("../wasm/sqlparser_rs_wasm.js", require("url").pathToFileURL(__filename).href).href
|
|
252
|
-
);
|
|
253
|
-
} catch (error) {
|
|
254
|
-
throw new WasmInitError(`Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`);
|
|
255
|
-
}
|
|
241
|
+
})();
|
|
242
|
+
await initPromise;
|
|
256
243
|
}
|
|
257
244
|
|
|
258
245
|
//#endregion
|
|
@@ -270,7 +257,7 @@ function resolveDialect(dialect = "generic") {
|
|
|
270
257
|
*
|
|
271
258
|
* @example
|
|
272
259
|
* ```typescript
|
|
273
|
-
* import { Parser, PostgreSqlDialect } from 'sqlparser-
|
|
260
|
+
* import { Parser, PostgreSqlDialect } from '@guanmingchiu/sqlparser-ts';
|
|
274
261
|
*
|
|
275
262
|
* const statements = Parser.parse('SELECT * FROM users', 'postgresql');
|
|
276
263
|
*
|
|
@@ -397,7 +384,6 @@ exports.SnowflakeDialect = SnowflakeDialect;
|
|
|
397
384
|
exports.WasmInitError = WasmInitError;
|
|
398
385
|
exports.dialectFromString = dialectFromString;
|
|
399
386
|
exports.format = format;
|
|
400
|
-
exports.
|
|
387
|
+
exports.init = init;
|
|
401
388
|
exports.parse = parse;
|
|
402
|
-
exports.ready = ready;
|
|
403
389
|
exports.validate = validate;
|
package/dist/index.d.cts
CHANGED
|
@@ -106,7 +106,7 @@ declare function dialectFromString(name: string): Dialect | undefined;
|
|
|
106
106
|
//#endregion
|
|
107
107
|
//#region src/types/ast.d.ts
|
|
108
108
|
/**
|
|
109
|
-
* TypeScript type definitions for sqlparser-
|
|
109
|
+
* TypeScript type definitions for sqlparser-ts AST
|
|
110
110
|
*
|
|
111
111
|
* These types mirror the Rust AST structure from the sqlparser crate.
|
|
112
112
|
* The AST is serialized as JSON from Rust, so these types represent
|
|
@@ -1204,14 +1204,10 @@ type CommentObject = 'Column' | 'Table';
|
|
|
1204
1204
|
//#endregion
|
|
1205
1205
|
//#region src/wasm.d.ts
|
|
1206
1206
|
/**
|
|
1207
|
-
*
|
|
1207
|
+
* Initialize the WASM module. Must be called before using any parser functions.
|
|
1208
|
+
* Safe to call multiple times, subsequent calls are no-ops.
|
|
1208
1209
|
*/
|
|
1209
|
-
declare function
|
|
1210
|
-
/**
|
|
1211
|
-
* Initialize the WASM module explicitly.
|
|
1212
|
-
* Usually not needed - the module auto-initializes on first use.
|
|
1213
|
-
*/
|
|
1214
|
-
declare function initWasm(): Promise<void>;
|
|
1210
|
+
declare function init(): Promise<void>;
|
|
1215
1211
|
//#endregion
|
|
1216
1212
|
//#region src/parser.d.ts
|
|
1217
1213
|
/** Dialect can be specified as a Dialect instance or a string name */
|
|
@@ -1230,7 +1226,7 @@ interface ParserOptions {
|
|
|
1230
1226
|
*
|
|
1231
1227
|
* @example
|
|
1232
1228
|
* ```typescript
|
|
1233
|
-
* import { Parser, PostgreSqlDialect } from 'sqlparser-
|
|
1229
|
+
* import { Parser, PostgreSqlDialect } from '@guanmingchiu/sqlparser-ts';
|
|
1234
1230
|
*
|
|
1235
1231
|
* const statements = Parser.parse('SELECT * FROM users', 'postgresql');
|
|
1236
1232
|
*
|
|
@@ -1306,4 +1302,4 @@ declare class WasmInitError extends Error {
|
|
|
1306
1302
|
constructor(message: string);
|
|
1307
1303
|
}
|
|
1308
1304
|
//#endregion
|
|
1309
|
-
export { Action, AlterColumnOperation, AlterTableOperation, AnsiDialect, Assignment, BigQueryDialect, BinaryOperator, ClickHouseDialect, CloseCursor, ColumnDef, ColumnOption, ColumnOptionDef, CommentObject, CopyLegacyOption, CopyOption, CopySource, CopyTarget, Cte, DataType, DatabricksDialect, DateTimeField, DescribeAlias, type Dialect, type DialectInput, type DialectName, DiscardObject, Distinct, DoUpdate, DropStatement, DuckDbDialect, ErrorLocation, ExceptSelectItem, ExcludeSelectItem, Expr, Fetch, FetchDirection, FileFormat, ForeignKeyOption, FunctionArg, FunctionArgExpr, FunctionExpr, GeneratedAs, GeneratedExpressionMode, GenericDialect, GrantObjects, GroupByExpr, HiveDialect, HiveDistributionStyle, HiveFormat, HiveIOFormat, HiveRowFormat, Ident, IdentWithAlias, IndexType, IntervalExpr, Join, JoinConstraint, JoinOperator, LateralView, LockClause, LockType, MergeClause, MsSqlDialect, MySqlDialect, NamedWindowDefinition, NonBlock, ObjectName, ObjectType, Offset, OffsetRows, OnCommit, OnInsert, OracleDialect, OrderByExpr, Parser, ParserError, type ParserOptions, PostgreSqlDialect, Privileges, Query, RedshiftDialect, ReferentialAction, RenameSelectItem, ReplaceSelectElement, ReplaceSelectItem, SQLiteDialect, SUPPORTED_DIALECTS, SchemaName, Select, SelectInto, SelectItem, SetExpr, SetOperator, SetQuantifier, ShowCreateObject, ShowStatementFilter, SnowflakeDialect, SqlOption, SqliteOnConflict, Statement, TableAlias, TableConstraint, TableFactor, TableWithJoins, Top, TransactionAccessMode, TransactionIsolationLevel, TransactionMode, TrimWhereField, UnaryOperator, Value, Values, WasmInitError, WildcardAdditionalOptions, WindowFrame, WindowFrameBound, WindowFrameUnits, WindowSpec, With, dialectFromString, format,
|
|
1305
|
+
export { Action, AlterColumnOperation, AlterTableOperation, AnsiDialect, Assignment, BigQueryDialect, BinaryOperator, ClickHouseDialect, CloseCursor, ColumnDef, ColumnOption, ColumnOptionDef, CommentObject, CopyLegacyOption, CopyOption, CopySource, CopyTarget, Cte, DataType, DatabricksDialect, DateTimeField, DescribeAlias, type Dialect, type DialectInput, type DialectName, DiscardObject, Distinct, DoUpdate, DropStatement, DuckDbDialect, ErrorLocation, ExceptSelectItem, ExcludeSelectItem, Expr, Fetch, FetchDirection, FileFormat, ForeignKeyOption, FunctionArg, FunctionArgExpr, FunctionExpr, GeneratedAs, GeneratedExpressionMode, GenericDialect, GrantObjects, GroupByExpr, HiveDialect, HiveDistributionStyle, HiveFormat, HiveIOFormat, HiveRowFormat, Ident, IdentWithAlias, IndexType, IntervalExpr, Join, JoinConstraint, JoinOperator, LateralView, LockClause, LockType, MergeClause, MsSqlDialect, MySqlDialect, NamedWindowDefinition, NonBlock, ObjectName, ObjectType, Offset, OffsetRows, OnCommit, OnInsert, OracleDialect, OrderByExpr, Parser, ParserError, type ParserOptions, PostgreSqlDialect, Privileges, Query, RedshiftDialect, ReferentialAction, RenameSelectItem, ReplaceSelectElement, ReplaceSelectItem, SQLiteDialect, SUPPORTED_DIALECTS, SchemaName, Select, SelectInto, SelectItem, SetExpr, SetOperator, SetQuantifier, ShowCreateObject, ShowStatementFilter, SnowflakeDialect, SqlOption, SqliteOnConflict, Statement, TableAlias, TableConstraint, TableFactor, TableWithJoins, Top, TransactionAccessMode, TransactionIsolationLevel, TransactionMode, TrimWhereField, UnaryOperator, Value, Values, WasmInitError, WildcardAdditionalOptions, WindowFrame, WindowFrameBound, WindowFrameUnits, WindowSpec, With, dialectFromString, format, init, parse, validate };
|
package/dist/index.d.mts
CHANGED
|
@@ -106,7 +106,7 @@ declare function dialectFromString(name: string): Dialect | undefined;
|
|
|
106
106
|
//#endregion
|
|
107
107
|
//#region src/types/ast.d.ts
|
|
108
108
|
/**
|
|
109
|
-
* TypeScript type definitions for sqlparser-
|
|
109
|
+
* TypeScript type definitions for sqlparser-ts AST
|
|
110
110
|
*
|
|
111
111
|
* These types mirror the Rust AST structure from the sqlparser crate.
|
|
112
112
|
* The AST is serialized as JSON from Rust, so these types represent
|
|
@@ -1204,14 +1204,10 @@ type CommentObject = 'Column' | 'Table';
|
|
|
1204
1204
|
//#endregion
|
|
1205
1205
|
//#region src/wasm.d.ts
|
|
1206
1206
|
/**
|
|
1207
|
-
*
|
|
1207
|
+
* Initialize the WASM module. Must be called before using any parser functions.
|
|
1208
|
+
* Safe to call multiple times, subsequent calls are no-ops.
|
|
1208
1209
|
*/
|
|
1209
|
-
declare function
|
|
1210
|
-
/**
|
|
1211
|
-
* Initialize the WASM module explicitly.
|
|
1212
|
-
* Usually not needed - the module auto-initializes on first use.
|
|
1213
|
-
*/
|
|
1214
|
-
declare function initWasm(): Promise<void>;
|
|
1210
|
+
declare function init(): Promise<void>;
|
|
1215
1211
|
//#endregion
|
|
1216
1212
|
//#region src/parser.d.ts
|
|
1217
1213
|
/** Dialect can be specified as a Dialect instance or a string name */
|
|
@@ -1230,7 +1226,7 @@ interface ParserOptions {
|
|
|
1230
1226
|
*
|
|
1231
1227
|
* @example
|
|
1232
1228
|
* ```typescript
|
|
1233
|
-
* import { Parser, PostgreSqlDialect } from 'sqlparser-
|
|
1229
|
+
* import { Parser, PostgreSqlDialect } from '@guanmingchiu/sqlparser-ts';
|
|
1234
1230
|
*
|
|
1235
1231
|
* const statements = Parser.parse('SELECT * FROM users', 'postgresql');
|
|
1236
1232
|
*
|
|
@@ -1306,4 +1302,4 @@ declare class WasmInitError extends Error {
|
|
|
1306
1302
|
constructor(message: string);
|
|
1307
1303
|
}
|
|
1308
1304
|
//#endregion
|
|
1309
|
-
export { Action, AlterColumnOperation, AlterTableOperation, AnsiDialect, Assignment, BigQueryDialect, BinaryOperator, ClickHouseDialect, CloseCursor, ColumnDef, ColumnOption, ColumnOptionDef, CommentObject, CopyLegacyOption, CopyOption, CopySource, CopyTarget, Cte, DataType, DatabricksDialect, DateTimeField, DescribeAlias, type Dialect, type DialectInput, type DialectName, DiscardObject, Distinct, DoUpdate, DropStatement, DuckDbDialect, ErrorLocation, ExceptSelectItem, ExcludeSelectItem, Expr, Fetch, FetchDirection, FileFormat, ForeignKeyOption, FunctionArg, FunctionArgExpr, FunctionExpr, GeneratedAs, GeneratedExpressionMode, GenericDialect, GrantObjects, GroupByExpr, HiveDialect, HiveDistributionStyle, HiveFormat, HiveIOFormat, HiveRowFormat, Ident, IdentWithAlias, IndexType, IntervalExpr, Join, JoinConstraint, JoinOperator, LateralView, LockClause, LockType, MergeClause, MsSqlDialect, MySqlDialect, NamedWindowDefinition, NonBlock, ObjectName, ObjectType, Offset, OffsetRows, OnCommit, OnInsert, OracleDialect, OrderByExpr, Parser, ParserError, type ParserOptions, PostgreSqlDialect, Privileges, Query, RedshiftDialect, ReferentialAction, RenameSelectItem, ReplaceSelectElement, ReplaceSelectItem, SQLiteDialect, SUPPORTED_DIALECTS, SchemaName, Select, SelectInto, SelectItem, SetExpr, SetOperator, SetQuantifier, ShowCreateObject, ShowStatementFilter, SnowflakeDialect, SqlOption, SqliteOnConflict, Statement, TableAlias, TableConstraint, TableFactor, TableWithJoins, Top, TransactionAccessMode, TransactionIsolationLevel, TransactionMode, TrimWhereField, UnaryOperator, Value, Values, WasmInitError, WildcardAdditionalOptions, WindowFrame, WindowFrameBound, WindowFrameUnits, WindowSpec, With, dialectFromString, format,
|
|
1305
|
+
export { Action, AlterColumnOperation, AlterTableOperation, AnsiDialect, Assignment, BigQueryDialect, BinaryOperator, ClickHouseDialect, CloseCursor, ColumnDef, ColumnOption, ColumnOptionDef, CommentObject, CopyLegacyOption, CopyOption, CopySource, CopyTarget, Cte, DataType, DatabricksDialect, DateTimeField, DescribeAlias, type Dialect, type DialectInput, type DialectName, DiscardObject, Distinct, DoUpdate, DropStatement, DuckDbDialect, ErrorLocation, ExceptSelectItem, ExcludeSelectItem, Expr, Fetch, FetchDirection, FileFormat, ForeignKeyOption, FunctionArg, FunctionArgExpr, FunctionExpr, GeneratedAs, GeneratedExpressionMode, GenericDialect, GrantObjects, GroupByExpr, HiveDialect, HiveDistributionStyle, HiveFormat, HiveIOFormat, HiveRowFormat, Ident, IdentWithAlias, IndexType, IntervalExpr, Join, JoinConstraint, JoinOperator, LateralView, LockClause, LockType, MergeClause, MsSqlDialect, MySqlDialect, NamedWindowDefinition, NonBlock, ObjectName, ObjectType, Offset, OffsetRows, OnCommit, OnInsert, OracleDialect, OrderByExpr, Parser, ParserError, type ParserOptions, PostgreSqlDialect, Privileges, Query, RedshiftDialect, ReferentialAction, RenameSelectItem, ReplaceSelectElement, ReplaceSelectItem, SQLiteDialect, SUPPORTED_DIALECTS, SchemaName, Select, SelectInto, SelectItem, SetExpr, SetOperator, SetQuantifier, ShowCreateObject, ShowStatementFilter, SnowflakeDialect, SqlOption, SqliteOnConflict, Statement, TableAlias, TableConstraint, TableFactor, TableWithJoins, Top, TransactionAccessMode, TransactionIsolationLevel, TransactionMode, TrimWhereField, UnaryOperator, Value, Values, WasmInitError, WildcardAdditionalOptions, WindowFrame, WindowFrameBound, WindowFrameUnits, WindowSpec, With, dialectFromString, format, init, parse, validate };
|
package/dist/index.mjs
CHANGED
|
@@ -203,55 +203,41 @@ var WasmInitError = class WasmInitError extends Error {
|
|
|
203
203
|
//#region src/wasm.ts
|
|
204
204
|
let wasmModule = null;
|
|
205
205
|
let initPromise = null;
|
|
206
|
-
let initStarted = false;
|
|
207
206
|
const isBrowser = typeof window !== "undefined" && typeof process === "undefined";
|
|
208
|
-
function startInit() {
|
|
209
|
-
if (initStarted) return;
|
|
210
|
-
initStarted = true;
|
|
211
|
-
initPromise = initWasm().catch(() => {});
|
|
212
|
-
}
|
|
213
|
-
startInit();
|
|
214
207
|
/** Get initialized WASM module or throw */
|
|
215
208
|
function getWasmModule() {
|
|
216
209
|
if (wasmModule) return wasmModule;
|
|
217
|
-
throw new WasmInitError("WASM module not yet initialized.
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Wait for WASM module to be ready
|
|
221
|
-
*/
|
|
222
|
-
async function ready() {
|
|
223
|
-
startInit();
|
|
224
|
-
await initPromise;
|
|
210
|
+
throw new WasmInitError("WASM module not yet initialized. Call `await init()` before using the parser.");
|
|
225
211
|
}
|
|
226
212
|
/**
|
|
227
|
-
* Initialize the WASM module
|
|
228
|
-
*
|
|
213
|
+
* Initialize the WASM module. Must be called before using any parser functions.
|
|
214
|
+
* Safe to call multiple times, subsequent calls are no-ops.
|
|
229
215
|
*/
|
|
230
|
-
async function
|
|
216
|
+
async function init() {
|
|
231
217
|
if (wasmModule) return;
|
|
232
|
-
if (
|
|
218
|
+
if (!initPromise) initPromise = (async () => {
|
|
233
219
|
try {
|
|
234
|
-
const wasmJsUrl = new URL("../wasm/sqlparser_rs_wasm_web.js", import.meta.url);
|
|
235
|
-
const wasmBinaryUrl = new URL("../wasm/sqlparser_rs_wasm_web_bg.wasm", import.meta.url);
|
|
236
220
|
const wasm = await import(
|
|
237
221
|
/* @vite-ignore */
|
|
238
|
-
|
|
222
|
+
"../wasm/sqlparser_rs_wasm.js"
|
|
239
223
|
);
|
|
240
|
-
if (
|
|
224
|
+
if (isBrowser) {
|
|
225
|
+
const wasmUrl = new URL("../wasm/sqlparser_rs_wasm_bg.wasm", import.meta.url);
|
|
226
|
+
await wasm.default({ module_or_path: wasmUrl });
|
|
227
|
+
} else {
|
|
228
|
+
const { readFile } = await import(
|
|
229
|
+
/* @vite-ignore */
|
|
230
|
+
"node:fs/promises"
|
|
231
|
+
);
|
|
232
|
+
const bytes = await readFile(new URL("../wasm/sqlparser_rs_wasm_bg.wasm", import.meta.url));
|
|
233
|
+
await wasm.default({ module_or_path: bytes });
|
|
234
|
+
}
|
|
241
235
|
wasmModule = wasm;
|
|
242
236
|
} catch (error) {
|
|
243
|
-
throw new WasmInitError(`Failed to load WASM module
|
|
237
|
+
throw new WasmInitError(`Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`);
|
|
244
238
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
try {
|
|
248
|
-
wasmModule = await import(
|
|
249
|
-
/* @vite-ignore */
|
|
250
|
-
new URL("../wasm/sqlparser_rs_wasm.js", import.meta.url).href
|
|
251
|
-
);
|
|
252
|
-
} catch (error) {
|
|
253
|
-
throw new WasmInitError(`Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`);
|
|
254
|
-
}
|
|
239
|
+
})();
|
|
240
|
+
await initPromise;
|
|
255
241
|
}
|
|
256
242
|
|
|
257
243
|
//#endregion
|
|
@@ -269,7 +255,7 @@ function resolveDialect(dialect = "generic") {
|
|
|
269
255
|
*
|
|
270
256
|
* @example
|
|
271
257
|
* ```typescript
|
|
272
|
-
* import { Parser, PostgreSqlDialect } from 'sqlparser-
|
|
258
|
+
* import { Parser, PostgreSqlDialect } from '@guanmingchiu/sqlparser-ts';
|
|
273
259
|
*
|
|
274
260
|
* const statements = Parser.parse('SELECT * FROM users', 'postgresql');
|
|
275
261
|
*
|
|
@@ -376,4 +362,4 @@ function format(sql, dialect = "generic") {
|
|
|
376
362
|
}
|
|
377
363
|
|
|
378
364
|
//#endregion
|
|
379
|
-
export { AnsiDialect, BigQueryDialect, ClickHouseDialect, DatabricksDialect, DuckDbDialect, GenericDialect, HiveDialect, MsSqlDialect, MySqlDialect, OracleDialect, Parser, ParserError, PostgreSqlDialect, RedshiftDialect, SQLiteDialect, SUPPORTED_DIALECTS, SnowflakeDialect, WasmInitError, dialectFromString, format,
|
|
365
|
+
export { AnsiDialect, BigQueryDialect, ClickHouseDialect, DatabricksDialect, DuckDbDialect, GenericDialect, HiveDialect, MsSqlDialect, MySqlDialect, OracleDialect, Parser, ParserError, PostgreSqlDialect, RedshiftDialect, SQLiteDialect, SUPPORTED_DIALECTS, SnowflakeDialect, WasmInitError, dialectFromString, format, init, parse, validate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sqlparser-rs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.61.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A SQL parser for JavaScript and TypeScript, powered by datafusion-sqlparser-rs via WASM",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "npm run build:wasm && npm run build:ts",
|
|
23
|
-
"build:wasm": "
|
|
24
|
-
"build:wasm:web": "cd .. && wasm-pack build --target web --out-dir ts/wasm-web",
|
|
23
|
+
"build:wasm": "wasm-pack build --target web --out-dir wasm && rm -f wasm/.gitignore",
|
|
25
24
|
"build:ts": "tsdown",
|
|
26
25
|
"test": "vitest run",
|
|
27
26
|
"test:watch": "vitest",
|
|
@@ -44,16 +43,15 @@
|
|
|
44
43
|
"license": "Apache-2.0",
|
|
45
44
|
"repository": {
|
|
46
45
|
"type": "git",
|
|
47
|
-
"url": "git+https://github.com/guan404ming/sqlparser-
|
|
46
|
+
"url": "git+https://github.com/guan404ming/sqlparser-ts.git"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
50
|
-
"@types/node": "^25.
|
|
51
|
-
"
|
|
52
|
-
"eslint": "^
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"typescript": "^
|
|
56
|
-
"typescript-eslint": "^8.21.0",
|
|
49
|
+
"@types/node": "^25.2.3",
|
|
50
|
+
"eslint": "^9.28.0",
|
|
51
|
+
"eslint-plugin-unused-imports": "^4.4.1",
|
|
52
|
+
"tsdown": "^0.20.3",
|
|
53
|
+
"typescript": "^5.9.3",
|
|
54
|
+
"typescript-eslint": "^8.55.0",
|
|
57
55
|
"vitest": "^4.0.18"
|
|
58
56
|
},
|
|
59
57
|
"engines": {
|