|
4 | 4 | // Based on the upstream glue with minimal changes for ESM + browsers. |
5 | 5 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
6 | 6 | // @ts-nocheck |
7 | | -import wasmUrl from "kite_sql/kite_sql_bg.wasm?url"; |
| 7 | +import wasmUrl from "@kipdata/kite_sql/kite_sql_bg.wasm?url"; |
8 | 8 |
|
9 | 9 | const placeholder: any = {}; |
10 | | -const imports: any = { __wbindgen_placeholder__: placeholder }; |
| 10 | +// The wasm expects its JS imports under the module name "./kite_sql_bg.js". |
| 11 | +const imports: any = { "./kite_sql_bg.js": placeholder }; |
11 | 12 | let wasm: any; |
12 | 13 |
|
13 | 14 | function addToExternrefTable0(obj) { |
@@ -189,23 +190,34 @@ class WasmResultIter { |
189 | 190 | free() { |
190 | 191 | const ptr = this.__destroy_into_raw(); |
191 | 192 | wasm.__wbg_wasmresultiter_free(ptr, 0); |
192 | | - } |
193 | | - /** |
194 | | - * Returns the next row as a JS object, or `undefined` when done. |
195 | | - * @returns {any} |
196 | | - */ |
197 | | - next() { |
198 | | - const ret = wasm.wasmresultiter_next(this.__wbg_ptr); |
199 | | - if (ret[2]) { |
200 | | - throw takeFromExternrefTable0(ret[1]); |
201 | 193 | } |
202 | | - return takeFromExternrefTable0(ret[0]); |
203 | | - } |
204 | | - /** |
205 | | - * Collect all remaining rows into an array and finish the iterator. |
206 | | - * @returns {any} |
207 | | - */ |
208 | | - rows() { |
| 194 | + /** |
| 195 | + * Returns the next row as a JS object, or `undefined` when done. |
| 196 | + * @returns {any} |
| 197 | + */ |
| 198 | + next() { |
| 199 | + const ret = wasm.wasmresultiter_next(this.__wbg_ptr); |
| 200 | + if (ret[2]) { |
| 201 | + throw takeFromExternrefTable0(ret[1]); |
| 202 | + } |
| 203 | + return takeFromExternrefTable0(ret[0]); |
| 204 | + } |
| 205 | + /** |
| 206 | + * Returns the output schema as an array of `{ name, datatype, nullable }`. |
| 207 | + * @returns {any} |
| 208 | + */ |
| 209 | + schema() { |
| 210 | + const ret = wasm.wasmresultiter_schema(this.__wbg_ptr); |
| 211 | + if (ret[2]) { |
| 212 | + throw takeFromExternrefTable0(ret[1]); |
| 213 | + } |
| 214 | + return takeFromExternrefTable0(ret[0]); |
| 215 | + } |
| 216 | + /** |
| 217 | + * Collect all remaining rows into an array and finish the iterator. |
| 218 | + * @returns {any} |
| 219 | + */ |
| 220 | + rows() { |
209 | 221 | const ret = wasm.wasmresultiter_rows(this.__wbg_ptr); |
210 | 222 | if (ret[2]) { |
211 | 223 | throw takeFromExternrefTable0(ret[1]); |
@@ -335,9 +347,10 @@ async function init(input = wasmUrl) { |
335 | 347 | const { instance, module } = await (async () => { |
336 | 348 | const res = await response; |
337 | 349 | if (res instanceof Response) { |
| 350 | + const resForStreaming = res.clone(); |
338 | 351 | if (typeof WebAssembly.instantiateStreaming === "function") { |
339 | 352 | try { |
340 | | - return await WebAssembly.instantiateStreaming(res, imports); |
| 353 | + return await WebAssembly.instantiateStreaming(resForStreaming, imports); |
341 | 354 | } catch (e) { |
342 | 355 | // Fallback if incorrect MIME type. |
343 | 356 | const bytes = await res.arrayBuffer(); |
|
0 commit comments