sqlparser-rs 0.60.4 → 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/wasm/README.md CHANGED
@@ -1,11 +1,12 @@
1
- # sqlparser-rs
1
+ # sqlparser-ts
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/sqlparser-rs.svg)](https://www.npmjs.com/package/sqlparser-rs)
3
+ [![npm version](https://img.shields.io/npm/v/@guanmingchiu/sqlparser-ts.svg)](https://www.npmjs.com/package/@guanmingchiu/sqlparser-ts)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@guanmingchiu/sqlparser-ts.svg)](https://www.npmjs.com/package/@guanmingchiu/sqlparser-ts)
4
5
  [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
5
6
  [![WebAssembly](https://img.shields.io/badge/WebAssembly-powered-blueviolet.svg)](https://webassembly.org/)
6
- [![sqlparser](https://img.shields.io/badge/sqlparser--rs-v0.60.0-orange.svg)](https://github.com/apache/datafusion-sqlparser-rs)
7
+ [![sqlparser](https://img.shields.io/badge/sqlparser--rs-v0.61.0-orange.svg)](https://github.com/apache/datafusion-sqlparser-rs)
7
8
 
8
- A SQL parser for JavaScript and TypeScript, powered by [datafusion-sqlparser-rs](https://github.com/apache/datafusion-sqlparser-rs) via WebAssembly.
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-rs
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-rs';
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/wasm/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "sqlparser-rs-wasm",
3
- "description": "WebAssembly bindings for sqlparser-rs SQL parser",
4
- "version": "0.60.4",
3
+ "type": "module",
4
+ "description": "WebAssembly bindings for sqlparser SQL parser",
5
+ "version": "0.61.1",
5
6
  "license": "Apache-2.0",
6
7
  "repository": {
7
8
  "type": "git",
8
- "url": "https://github.com/guan404ming/sqlparser-rs"
9
+ "url": "https://github.com/guanmingchiu/sqlparser-ts"
9
10
  },
10
11
  "files": [
11
12
  "sqlparser_rs_wasm_bg.wasm",
@@ -13,5 +14,8 @@
13
14
  "sqlparser_rs_wasm.d.ts"
14
15
  ],
15
16
  "main": "sqlparser_rs_wasm.js",
16
- "types": "sqlparser_rs_wasm.d.ts"
17
+ "types": "sqlparser_rs_wasm.d.ts",
18
+ "sideEffects": [
19
+ "./snippets/*"
20
+ ]
17
21
  }
@@ -37,3 +37,47 @@ export function parse_sql_with_options(dialect: string, sql: string, options: an
37
37
  * Validate SQL syntax without returning the full AST
38
38
  */
39
39
  export function validate_sql(dialect: string, sql: string): boolean;
40
+
41
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
42
+
43
+ export interface InitOutput {
44
+ readonly memory: WebAssembly.Memory;
45
+ readonly format_sql: (a: number, b: number, c: number, d: number) => [number, number, number, number];
46
+ readonly get_supported_dialects: () => any;
47
+ readonly init: () => void;
48
+ readonly parse_sql: (a: number, b: number, c: number, d: number) => [number, number, number];
49
+ readonly parse_sql_to_json_string: (a: number, b: number, c: number, d: number) => [number, number, number, number];
50
+ readonly parse_sql_to_string: (a: number, b: number, c: number, d: number) => [number, number, number, number];
51
+ readonly parse_sql_with_options: (a: number, b: number, c: number, d: number, e: any) => [number, number, number];
52
+ readonly validate_sql: (a: number, b: number, c: number, d: number) => [number, number, number];
53
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
54
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
55
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
56
+ readonly __wbindgen_exn_store: (a: number) => void;
57
+ readonly __externref_table_alloc: () => number;
58
+ readonly __wbindgen_externrefs: WebAssembly.Table;
59
+ readonly __externref_table_dealloc: (a: number) => void;
60
+ readonly __wbindgen_start: () => void;
61
+ }
62
+
63
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
64
+
65
+ /**
66
+ * Instantiates the given `module`, which can either be bytes or
67
+ * a precompiled `WebAssembly.Module`.
68
+ *
69
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
70
+ *
71
+ * @returns {InitOutput}
72
+ */
73
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
74
+
75
+ /**
76
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
77
+ * for everything else, calls `WebAssembly.instantiate` directly.
78
+ *
79
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
80
+ *
81
+ * @returns {Promise<InitOutput>}
82
+ */
83
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -6,7 +6,7 @@
6
6
  * @param {string} sql
7
7
  * @returns {string}
8
8
  */
9
- function format_sql(dialect, sql) {
9
+ export function format_sql(dialect, sql) {
10
10
  let deferred4_0;
11
11
  let deferred4_1;
12
12
  try {
@@ -28,22 +28,19 @@ function format_sql(dialect, sql) {
28
28
  wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
29
29
  }
30
30
  }
31
- exports.format_sql = format_sql;
32
31
 
33
32
  /**
34
33
  * Get a list of all supported dialect names
35
34
  * @returns {any}
36
35
  */
37
- function get_supported_dialects() {
36
+ export function get_supported_dialects() {
38
37
  const ret = wasm.get_supported_dialects();
39
38
  return ret;
40
39
  }
41
- exports.get_supported_dialects = get_supported_dialects;
42
40
 
43
- function init() {
41
+ export function init() {
44
42
  wasm.init();
45
43
  }
46
- exports.init = init;
47
44
 
48
45
  /**
49
46
  * Parse SQL and return the AST as a JSON value
@@ -51,7 +48,7 @@ exports.init = init;
51
48
  * @param {string} sql
52
49
  * @returns {any}
53
50
  */
54
- function parse_sql(dialect, sql) {
51
+ export function parse_sql(dialect, sql) {
55
52
  const ptr0 = passStringToWasm0(dialect, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
56
53
  const len0 = WASM_VECTOR_LEN;
57
54
  const ptr1 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -62,7 +59,6 @@ function parse_sql(dialect, sql) {
62
59
  }
63
60
  return takeFromExternrefTable0(ret[0]);
64
61
  }
65
- exports.parse_sql = parse_sql;
66
62
 
67
63
  /**
68
64
  * Parse SQL and return the AST as a JSON string
@@ -70,7 +66,7 @@ exports.parse_sql = parse_sql;
70
66
  * @param {string} sql
71
67
  * @returns {string}
72
68
  */
73
- function parse_sql_to_json_string(dialect, sql) {
69
+ export function parse_sql_to_json_string(dialect, sql) {
74
70
  let deferred4_0;
75
71
  let deferred4_1;
76
72
  try {
@@ -92,7 +88,6 @@ function parse_sql_to_json_string(dialect, sql) {
92
88
  wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
93
89
  }
94
90
  }
95
- exports.parse_sql_to_json_string = parse_sql_to_json_string;
96
91
 
97
92
  /**
98
93
  * Parse SQL and return a string representation of the AST
@@ -100,7 +95,7 @@ exports.parse_sql_to_json_string = parse_sql_to_json_string;
100
95
  * @param {string} sql
101
96
  * @returns {string}
102
97
  */
103
- function parse_sql_to_string(dialect, sql) {
98
+ export function parse_sql_to_string(dialect, sql) {
104
99
  let deferred4_0;
105
100
  let deferred4_1;
106
101
  try {
@@ -122,7 +117,6 @@ function parse_sql_to_string(dialect, sql) {
122
117
  wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
123
118
  }
124
119
  }
125
- exports.parse_sql_to_string = parse_sql_to_string;
126
120
 
127
121
  /**
128
122
  * Parse SQL with options and return the AST as a JSON value
@@ -131,7 +125,7 @@ exports.parse_sql_to_string = parse_sql_to_string;
131
125
  * @param {any} options
132
126
  * @returns {any}
133
127
  */
134
- function parse_sql_with_options(dialect, sql, options) {
128
+ export function parse_sql_with_options(dialect, sql, options) {
135
129
  const ptr0 = passStringToWasm0(dialect, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
136
130
  const len0 = WASM_VECTOR_LEN;
137
131
  const ptr1 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -142,7 +136,6 @@ function parse_sql_with_options(dialect, sql, options) {
142
136
  }
143
137
  return takeFromExternrefTable0(ret[0]);
144
138
  }
145
- exports.parse_sql_with_options = parse_sql_with_options;
146
139
 
147
140
  /**
148
141
  * Validate SQL syntax without returning the full AST
@@ -150,7 +143,7 @@ exports.parse_sql_with_options = parse_sql_with_options;
150
143
  * @param {string} sql
151
144
  * @returns {boolean}
152
145
  */
153
- function validate_sql(dialect, sql) {
146
+ export function validate_sql(dialect, sql) {
154
147
  const ptr0 = passStringToWasm0(dialect, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
155
148
  const len0 = WASM_VECTOR_LEN;
156
149
  const ptr1 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -161,7 +154,6 @@ function validate_sql(dialect, sql) {
161
154
  }
162
155
  return ret[0] !== 0;
163
156
  }
164
- exports.validate_sql = validate_sql;
165
157
 
166
158
  function __wbg_get_imports() {
167
159
  const import0 = {
@@ -515,7 +507,15 @@ function takeFromExternrefTable0(idx) {
515
507
 
516
508
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
517
509
  cachedTextDecoder.decode();
510
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
511
+ let numBytesDecoded = 0;
518
512
  function decodeText(ptr, len) {
513
+ numBytesDecoded += len;
514
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
515
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
516
+ cachedTextDecoder.decode();
517
+ numBytesDecoded = len;
518
+ }
519
519
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
520
520
  }
521
521
 
@@ -534,8 +534,95 @@ if (!('encodeInto' in cachedTextEncoder)) {
534
534
 
535
535
  let WASM_VECTOR_LEN = 0;
536
536
 
537
- const wasmPath = `${__dirname}/sqlparser_rs_wasm_bg.wasm`;
538
- const wasmBytes = require('fs').readFileSync(wasmPath);
539
- const wasmModule = new WebAssembly.Module(wasmBytes);
540
- const wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
541
- wasm.__wbindgen_start();
537
+ let wasmModule, wasm;
538
+ function __wbg_finalize_init(instance, module) {
539
+ wasm = instance.exports;
540
+ wasmModule = module;
541
+ cachedDataViewMemory0 = null;
542
+ cachedUint8ArrayMemory0 = null;
543
+ wasm.__wbindgen_start();
544
+ return wasm;
545
+ }
546
+
547
+ async function __wbg_load(module, imports) {
548
+ if (typeof Response === 'function' && module instanceof Response) {
549
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
550
+ try {
551
+ return await WebAssembly.instantiateStreaming(module, imports);
552
+ } catch (e) {
553
+ const validResponse = module.ok && expectedResponseType(module.type);
554
+
555
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
556
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
557
+
558
+ } else { throw e; }
559
+ }
560
+ }
561
+
562
+ const bytes = await module.arrayBuffer();
563
+ return await WebAssembly.instantiate(bytes, imports);
564
+ } else {
565
+ const instance = await WebAssembly.instantiate(module, imports);
566
+
567
+ if (instance instanceof WebAssembly.Instance) {
568
+ return { instance, module };
569
+ } else {
570
+ return instance;
571
+ }
572
+ }
573
+
574
+ function expectedResponseType(type) {
575
+ switch (type) {
576
+ case 'basic': case 'cors': case 'default': return true;
577
+ }
578
+ return false;
579
+ }
580
+ }
581
+
582
+ function initSync(module) {
583
+ if (wasm !== undefined) return wasm;
584
+
585
+
586
+ if (module !== undefined) {
587
+ if (Object.getPrototypeOf(module) === Object.prototype) {
588
+ ({module} = module)
589
+ } else {
590
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
591
+ }
592
+ }
593
+
594
+ const imports = __wbg_get_imports();
595
+ if (!(module instanceof WebAssembly.Module)) {
596
+ module = new WebAssembly.Module(module);
597
+ }
598
+ const instance = new WebAssembly.Instance(module, imports);
599
+ return __wbg_finalize_init(instance, module);
600
+ }
601
+
602
+ async function __wbg_init(module_or_path) {
603
+ if (wasm !== undefined) return wasm;
604
+
605
+
606
+ if (module_or_path !== undefined) {
607
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
608
+ ({module_or_path} = module_or_path)
609
+ } else {
610
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
611
+ }
612
+ }
613
+
614
+ if (module_or_path === undefined) {
615
+ module_or_path = new URL('sqlparser_rs_wasm_bg.wasm', import.meta.url);
616
+ }
617
+ const imports = __wbg_get_imports();
618
+
619
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
620
+ module_or_path = fetch(module_or_path);
621
+ }
622
+
623
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
624
+
625
+ return __wbg_finalize_init(instance, module);
626
+ }
627
+
628
+ export { initSync, __wbg_init as default };
Binary file