@gscdump/engine-duckdb-wasm 0.38.1 → 0.39.0

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 (2) hide show
  1. package/dist/index.mjs +30 -6
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -797,17 +797,40 @@ async function materialiseFile(root, name, file, fetchImpl, fetchInit, signal) {
797
797
  signal: fetchSignal
798
798
  });
799
799
  if (!resp.ok) throw new Error(`[engine-duckdb-wasm/opfs] download ${file.url} failed: ${resp.status}`);
800
- const buf = await resp.arrayBuffer();
801
- if (buf.byteLength !== file.bytes) throw new Error(`[engine-duckdb-wasm/opfs] download ${file.url} byte length mismatch: expected ${file.bytes}, got ${buf.byteLength}`);
802
800
  handle = await root.getFileHandle(name, { create: true });
803
- const writable = await handle.createWritable();
801
+ let writable;
804
802
  try {
805
- await writable.write(buf);
803
+ writable = await handle.createWritable();
804
+ } catch (err) {
805
+ await resp.body?.cancel().catch(() => void 0);
806
+ throw err;
807
+ }
808
+ let reader;
809
+ let bytesWritten = 0;
810
+ try {
811
+ if (resp.body) {
812
+ reader = resp.body.getReader();
813
+ while (true) {
814
+ const { done, value } = await reader.read();
815
+ if (done) break;
816
+ bytesWritten += value.byteLength;
817
+ if (bytesWritten > file.bytes) throw new Error(`[engine-duckdb-wasm/opfs] download ${file.url} byte length mismatch: expected ${file.bytes}, got more than ${file.bytes}`);
818
+ await writable.write(value);
819
+ }
820
+ } else {
821
+ const buf = await resp.arrayBuffer();
822
+ bytesWritten = buf.byteLength;
823
+ await writable.write(buf);
824
+ }
825
+ if (bytesWritten !== file.bytes) throw new Error(`[engine-duckdb-wasm/opfs] download ${file.url} byte length mismatch: expected ${file.bytes}, got ${bytesWritten}`);
806
826
  await writable.close();
807
827
  } catch (err) {
828
+ await reader?.cancel().catch(() => void 0);
808
829
  if (writable.abort) await attemptCleanup(`aborting partial OPFS write ${name}`, () => writable.abort());
809
830
  await attemptCleanup(`removing partial OPFS file ${name}`, () => root.removeEntry(name));
810
831
  throw err;
832
+ } finally {
833
+ reader?.releaseLock();
811
834
  }
812
835
  return {
813
836
  handle,
@@ -828,7 +851,7 @@ function readParquetViewWithOverlaySql(schema, table, lakeFiles, overlayFile) {
828
851
  return `CREATE OR REPLACE VIEW ${schema}.${table} AS ${overlayViewBody({
829
852
  lakeSelect: lakeFiles.length === 0 ? null : lakeSelect(lakeFiles),
830
853
  overlaySelect: overlay,
831
- materializeLake: true
854
+ materializeLake: false
832
855
  })}`;
833
856
  }
834
857
  function viewKey(schema, table) {
@@ -1237,7 +1260,8 @@ async function runWithConcurrency(items, concurrency, fn) {
1237
1260
  }
1238
1261
  }
1239
1262
  }
1240
- await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, worker));
1263
+ const rejected = (await Promise.allSettled(Array.from({ length: Math.min(concurrency, items.length) }, worker))).find((result) => result.status === "rejected");
1264
+ if (rejected) throw rejected.reason;
1241
1265
  }
1242
1266
  function sizeHintFromUrl(url) {
1243
1267
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gscdump/engine-duckdb-wasm",
3
3
  "type": "module",
4
- "version": "0.38.1",
4
+ "version": "0.39.0",
5
5
  "description": "DuckDB-WASM engine adapter for @gscdump/analysis — typed browser analytics against parquet via R2.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -45,9 +45,9 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "drizzle-orm": "1.0.0-rc.3",
48
- "@gscdump/contracts": "0.38.1",
49
- "gscdump": "0.38.1",
50
- "@gscdump/engine": "0.38.1"
48
+ "@gscdump/engine": "0.39.0",
49
+ "@gscdump/contracts": "0.39.0",
50
+ "gscdump": "0.39.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@duckdb/duckdb-wasm": "^1.32.0",