@hpcc-js/wasm-duckdb 1.15.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.15.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": "81504905bd26f44c1e68b31760269dee081c0cbb"
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,7 +91,7 @@ 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
- export class DuckDB extends MainModuleEx<MainModule> implements Disposable {
94
+ export class DuckDB extends MainModuleEx<MainModule> {
95
95
 
96
96
  db: CPPDuckDB
97
97
 
@@ -103,47 +103,6 @@ export class DuckDB extends MainModuleEx<MainModule> implements Disposable {
103
103
  FS_createPath("/", "home/web_user", true, true);
104
104
  }
105
105
 
106
- /**
107
- * Disposes of the DuckDB database instance and releases resources.
108
- *
109
- * This method should be called when you're done using the database to free up
110
- * memory and clean up resources. After calling dispose, the instance should not be used.
111
- *
112
- * @example
113
- * ```ts
114
- * const duckdb = await DuckDB.load();
115
- * const connection = duckdb.connect();
116
- * // ... use the database ...
117
- * connection.delete();
118
- * duckdb.dispose();
119
- * ```
120
- *
121
- * @example Using statement (TypeScript 5.2+)
122
- * ```ts
123
- * {
124
- * using duckdb = await DuckDB.load();
125
- * const connection = duckdb.connect();
126
- * // ... use the database ...
127
- * connection.delete();
128
- * } // duckdb.dispose() is called automatically
129
- * ```
130
- */
131
- dispose(): void {
132
- try {
133
- this.db?.terminate();
134
- } finally {
135
- this.db?.delete();
136
- }
137
- }
138
-
139
- /**
140
- * Symbol.dispose implementation for use with `using` declarations.
141
- * @internal
142
- */
143
- [Symbol.dispose](): void {
144
- this.dispose();
145
- }
146
-
147
106
  /**
148
107
  * Loads and initializes the DuckDB WASM module.
149
108
  *
@@ -167,7 +126,7 @@ export class DuckDB extends MainModuleEx<MainModule> implements Disposable {
167
126
  return new DuckDB(module)
168
127
  });
169
128
  }
170
- return g_duckdb;
129
+ return g_duckdb!;
171
130
  }
172
131
 
173
132
  /**
@@ -182,8 +141,20 @@ export class DuckDB extends MainModuleEx<MainModule> implements Disposable {
182
141
  * // The next call to DuckDB.load() will create a fresh instance
183
142
  * ```
184
143
  */
185
- static unload() {
186
- 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
+ }
187
158
  }
188
159
 
189
160
  /**
@@ -240,6 +211,27 @@ export class DuckDB extends MainModuleEx<MainModule> implements Disposable {
240
211
  return Number(this.db.numberOfThreads());
241
212
  }
242
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
+
243
235
  /**
244
236
  * Registers a binary file in the virtual file system.
245
237
  *
@@ -371,5 +363,5 @@ export class DuckDB extends MainModuleEx<MainModule> implements Disposable {
371
363
  const encoded = textEncoder.encode(content);
372
364
  this.registerFile(fileName, encoded);
373
365
  }
374
-
375
366
  }
367
+
package/types/duckdb.d.ts CHANGED
@@ -85,40 +85,9 @@ import { MainModuleEx } from "@hpcc-js/wasm-util";
85
85
  * @see [DuckDB Documentation](https://duckdb.org/docs/)
86
86
  * @see [DuckDB GitHub](https://github.com/duckdb/duckdb)
87
87
  */
88
- export declare class DuckDB extends MainModuleEx<MainModule> implements Disposable {
88
+ export declare class DuckDB extends MainModuleEx<MainModule> {
89
89
  db: CPPDuckDB;
90
90
  private constructor();
91
- /**
92
- * Disposes of the DuckDB database instance and releases resources.
93
- *
94
- * This method should be called when you're done using the database to free up
95
- * memory and clean up resources. After calling dispose, the instance should not be used.
96
- *
97
- * @example
98
- * ```ts
99
- * const duckdb = await DuckDB.load();
100
- * const connection = duckdb.connect();
101
- * // ... use the database ...
102
- * connection.delete();
103
- * duckdb.dispose();
104
- * ```
105
- *
106
- * @example Using statement (TypeScript 5.2+)
107
- * ```ts
108
- * {
109
- * using duckdb = await DuckDB.load();
110
- * const connection = duckdb.connect();
111
- * // ... use the database ...
112
- * connection.delete();
113
- * } // duckdb.dispose() is called automatically
114
- * ```
115
- */
116
- dispose(): void;
117
- /**
118
- * Symbol.dispose implementation for use with `using` declarations.
119
- * @internal
120
- */
121
- [Symbol.dispose](): void;
122
91
  /**
123
92
  * Loads and initializes the DuckDB WASM module.
124
93
  *
@@ -149,7 +118,7 @@ export declare class DuckDB extends MainModuleEx<MainModule> implements Disposab
149
118
  * // The next call to DuckDB.load() will create a fresh instance
150
119
  * ```
151
120
  */
152
- static unload(): void;
121
+ static unload(): Promise<void>;
153
122
  /**
154
123
  * Returns the DuckDB version string.
155
124
  *
@@ -195,6 +164,10 @@ export declare class DuckDB extends MainModuleEx<MainModule> implements Disposab
195
164
  * ```
196
165
  */
197
166
  numberOfThreads(): number;
167
+ getExceptionMessage(error: unknown): {
168
+ type: string;
169
+ message?: string;
170
+ };
198
171
  /**
199
172
  * Registers a binary file in the virtual file system.
200
173
  *