@hpcc-js/wasm-duckdb 1.14.0 → 1.16.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpcc-js/wasm-duckdb",
3
- "version": "1.14.0",
3
+ "version": "1.16.0",
4
4
  "description": "hpcc-js - WASM DuckDB",
5
5
  "type": "module",
6
6
  "exports": {
@@ -27,6 +27,7 @@
27
27
  "bundle-watch": "npm run bundle-dev -- --watch",
28
28
  "build-dev": "run-p gen-types bundle-dev",
29
29
  "build": "run-p gen-types bundle",
30
+ "build-all": "run-s build-cpp gen-types bundle",
30
31
  "lint-skypack": "npx -y @skypack/package-check",
31
32
  "lint-eslint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\"",
32
33
  "lint": "run-p lint-eslint",
@@ -55,5 +56,5 @@
55
56
  },
56
57
  "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
57
58
  "license": "Apache-2.0",
58
- "gitHead": "e34abaa76d55e43967e9da38228c28d75dd4d43a"
59
+ "gitHead": "f539a56609708635b900faf022e9384707b1003c"
59
60
  }
package/src/duckdb.ts CHANGED
@@ -3,7 +3,7 @@ import load, { reset } from "../../../build/packages/duckdb/duckdblib.wasm";
3
3
  import type { MainModule, DuckDB as CPPDuckDB } from "../types/duckdblib.js";
4
4
  import { MainModuleEx } from "@hpcc-js/wasm-util";
5
5
 
6
- let g_duckdb: Promise<DuckDB>;
6
+ let g_duckdb: Promise<DuckDB> | undefined;
7
7
  const textEncoder = new TextEncoder();
8
8
 
9
9
  /**
@@ -91,9 +91,6 @@ const textEncoder = new TextEncoder();
91
91
  * @see [DuckDB Documentation](https://duckdb.org/docs/)
92
92
  * @see [DuckDB GitHub](https://github.com/duckdb/duckdb)
93
93
  */
94
-
95
-
96
-
97
94
  export class DuckDB extends MainModuleEx<MainModule> {
98
95
 
99
96
  db: CPPDuckDB
@@ -101,6 +98,7 @@ export class DuckDB extends MainModuleEx<MainModule> {
101
98
  private constructor(_module: MainModule) {
102
99
  super(_module);
103
100
  this.db = this._module.create()!;
101
+ // Special home directory for web_user (needed for some extensions)
104
102
  const { FS_createPath } = this._module;
105
103
  FS_createPath("/", "home/web_user", true, true);
106
104
  }
@@ -128,7 +126,7 @@ export class DuckDB extends MainModuleEx<MainModule> {
128
126
  return new DuckDB(module)
129
127
  });
130
128
  }
131
- return g_duckdb;
129
+ return g_duckdb!;
132
130
  }
133
131
 
134
132
  /**
@@ -143,8 +141,20 @@ export class DuckDB extends MainModuleEx<MainModule> {
143
141
  * // The next call to DuckDB.load() will create a fresh instance
144
142
  * ```
145
143
  */
146
- static unload() {
147
- reset();
144
+ static async unload() {
145
+ try {
146
+ const duckdb = await g_duckdb;
147
+ if (duckdb?.db) {
148
+ try {
149
+ duckdb.db.terminate();
150
+ } finally {
151
+ duckdb.db.delete();
152
+ }
153
+ }
154
+ } finally {
155
+ reset();
156
+ g_duckdb = undefined;
157
+ }
148
158
  }
149
159
 
150
160
  /**
@@ -201,6 +211,27 @@ export class DuckDB extends MainModuleEx<MainModule> {
201
211
  return Number(this.db.numberOfThreads());
202
212
  }
203
213
 
214
+ getExceptionMessage(error: unknown): { type: string, message?: string } {
215
+ const mod: any = this._module as any;
216
+ try {
217
+ const result = mod?.getExceptionMessage?.(error);
218
+ if (Array.isArray(result)) {
219
+ return {
220
+ type: result[0] ?? "",
221
+ message: result[1] ?? ""
222
+ };
223
+ }
224
+ } catch (_err) {
225
+ void _err;
226
+ }
227
+
228
+ const err: any = error;
229
+ return {
230
+ type: err?.name ?? "Error",
231
+ message: typeof err?.message === "string" ? err.message : String(error)
232
+ };
233
+ }
234
+
204
235
  /**
205
236
  * Registers a binary file in the virtual file system.
206
237
  *
@@ -332,5 +363,5 @@ export class DuckDB extends MainModuleEx<MainModule> {
332
363
  const encoded = textEncoder.encode(content);
333
364
  this.registerFile(fileName, encoded);
334
365
  }
335
-
336
366
  }
367
+
package/types/duckdb.d.ts CHANGED
@@ -118,7 +118,7 @@ export declare class DuckDB extends MainModuleEx<MainModule> {
118
118
  * // The next call to DuckDB.load() will create a fresh instance
119
119
  * ```
120
120
  */
121
- static unload(): void;
121
+ static unload(): Promise<void>;
122
122
  /**
123
123
  * Returns the DuckDB version string.
124
124
  *
@@ -164,6 +164,10 @@ export declare class DuckDB extends MainModuleEx<MainModule> {
164
164
  * ```
165
165
  */
166
166
  numberOfThreads(): number;
167
+ getExceptionMessage(error: unknown): {
168
+ type: string;
169
+ message?: string;
170
+ };
167
171
  /**
168
172
  * Registers a binary file in the virtual file system.
169
173
  *