@hpcc-js/wasm-duckdb 1.13.0 → 1.14.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.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "hpcc-js - WASM DuckDB",
5
5
  "type": "module",
6
6
  "exports": {
@@ -38,7 +38,7 @@
38
38
  "update-major": "npx -y npm-check-updates -u"
39
39
  },
40
40
  "devDependencies": {
41
- "@hpcc-js/esbuild-plugins": "1.7.0",
41
+ "@hpcc-js/esbuild-plugins": "1.8.0",
42
42
  "@hpcc-js/wasm-util": "1.0.0"
43
43
  },
44
44
  "keywords": [
@@ -55,5 +55,5 @@
55
55
  },
56
56
  "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
57
57
  "license": "Apache-2.0",
58
- "gitHead": "6799e024fc9186c4a4f87294862142f00628e597"
58
+ "gitHead": "e34abaa76d55e43967e9da38228c28d75dd4d43a"
59
59
  }
package/src/duckdb.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // @ts-expect-error importing from a wasm file is resolved via a custom esbuild plugin
2
2
  import load, { reset } from "../../../build/packages/duckdb/duckdblib.wasm";
3
- import type { MainModule, DuckDB as CPPDuckDB } from "../../../build/packages/duckdb/duckdblib.js";
3
+ import type { MainModule, DuckDB as CPPDuckDB } from "../types/duckdblib.js";
4
4
  import { MainModuleEx } from "@hpcc-js/wasm-util";
5
5
 
6
6
  let g_duckdb: Promise<DuckDB>;
@@ -229,13 +229,61 @@ export class DuckDB extends MainModuleEx<MainModule> {
229
229
  registerFile(path: string, content: Uint8Array): void {
230
230
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
231
231
  const split = normalizedPath.lastIndexOf("/");
232
- const dir = split > 0 ? normalizedPath.substring(0, split) : "/";
233
- if (dir.length > 1 && this._module.FS_createPath) {
234
- this._module.FS_createPath(dir, true, true);
232
+ if (split > 0) {
233
+ const dir = normalizedPath.substring(0, split);
234
+ const parts = dir.split("/");
235
+ let currentPath = "/";
236
+ for (const part of parts) {
237
+ if (part && this._module.FS_createPath) {
238
+ this._module.FS_createPath(currentPath, part, true, true);
239
+ currentPath = currentPath === "/" ? "/" + part : currentPath + "/" + part;
240
+ }
241
+ }
235
242
  }
236
243
  this._module.FS_createDataFile(normalizedPath, undefined, content, true, true, true);
237
244
  }
238
245
 
246
+ /**
247
+ * Unregisters and removes a file from the virtual file system.
248
+ *
249
+ * This removes a file that was previously registered using {@link registerFile} or
250
+ * {@link registerFileString}. Once unregistered, the file will no longer be accessible
251
+ * to DuckDB queries.
252
+ *
253
+ * The path is normalized to remove leading slashes before removal.
254
+ *
255
+ * @param path - The path of the file to remove (e.g., "data/users.csv")
256
+ *
257
+ * @example
258
+ * ```ts
259
+ * const duckdb = await DuckDB.load();
260
+ *
261
+ * // Register a file
262
+ * duckdb.registerFileString("temp.csv", "id,name\n1,Alice");
263
+ *
264
+ * const connection = duckdb.connect();
265
+ * let result = connection.query("SELECT * FROM read_csv_auto('temp.csv')");
266
+ * console.log(result.rowCount()); // 1
267
+ * result.delete();
268
+ *
269
+ * // Unregister the file
270
+ * duckdb.unregisterFile("temp.csv");
271
+ *
272
+ * // File is no longer accessible
273
+ * try {
274
+ * result = connection.query("SELECT * FROM read_csv_auto('temp.csv')");
275
+ * } catch (error) {
276
+ * console.error("File not found"); // Error: file not accessible
277
+ * }
278
+ *
279
+ * connection.delete();
280
+ * ```
281
+ */
282
+ unregisterFile(path: string): void {
283
+ const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
284
+ this._module.FS_unlink(normalizedPath);
285
+ }
286
+
239
287
  /**
240
288
  * Registers a text file in the virtual file system.
241
289
  *
package/types/duckdb.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { MainModule, DuckDB as CPPDuckDB } from "../../../build/packages/duckdb/duckdblib.js";
1
+ import type { MainModule, DuckDB as CPPDuckDB } from "../types/duckdblib.js";
2
2
  import { MainModuleEx } from "@hpcc-js/wasm-util";
3
3
  /**
4
4
  * DuckDB WASM library - an in-process SQL OLAP Database Management System.
@@ -151,7 +151,7 @@ export declare class DuckDB extends MainModuleEx<MainModule> {
151
151
  * connection.delete(); // Important: clean up!
152
152
  * ```
153
153
  */
154
- connect(): import("../../../build/packages/duckdb/duckdblib.js").Connection;
154
+ connect(): import("../types/duckdblib.js").Connection;
155
155
  /**
156
156
  * Returns the number of threads available to DuckDB.
157
157
  *
@@ -190,6 +190,43 @@ export declare class DuckDB extends MainModuleEx<MainModule> {
190
190
  * ```
191
191
  */
192
192
  registerFile(path: string, content: Uint8Array): void;
193
+ /**
194
+ * Unregisters and removes a file from the virtual file system.
195
+ *
196
+ * This removes a file that was previously registered using {@link registerFile} or
197
+ * {@link registerFileString}. Once unregistered, the file will no longer be accessible
198
+ * to DuckDB queries.
199
+ *
200
+ * The path is normalized to remove leading slashes before removal.
201
+ *
202
+ * @param path - The path of the file to remove (e.g., "data/users.csv")
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * const duckdb = await DuckDB.load();
207
+ *
208
+ * // Register a file
209
+ * duckdb.registerFileString("temp.csv", "id,name\n1,Alice");
210
+ *
211
+ * const connection = duckdb.connect();
212
+ * let result = connection.query("SELECT * FROM read_csv_auto('temp.csv')");
213
+ * console.log(result.rowCount()); // 1
214
+ * result.delete();
215
+ *
216
+ * // Unregister the file
217
+ * duckdb.unregisterFile("temp.csv");
218
+ *
219
+ * // File is no longer accessible
220
+ * try {
221
+ * result = connection.query("SELECT * FROM read_csv_auto('temp.csv')");
222
+ * } catch (error) {
223
+ * console.error("File not found"); // Error: file not accessible
224
+ * }
225
+ *
226
+ * connection.delete();
227
+ * ```
228
+ */
229
+ unregisterFile(path: string): void;
193
230
  /**
194
231
  * Registers a text file in the virtual file system.
195
232
  *
@@ -0,0 +1,171 @@
1
+ // TypeScript bindings for emscripten-generated code. Automatically generated at compile time.
2
+ declare namespace RuntimeExports {
3
+ /**
4
+ * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
5
+ * emscripten HEAP, returns a copy of that string as a Javascript String object.
6
+ *
7
+ * @param {number} ptr
8
+ * @param {number=} maxBytesToRead - An optional length that specifies the
9
+ * maximum number of bytes to read. You can omit this parameter to scan the
10
+ * string until the first 0 byte. If maxBytesToRead is passed, and the string
11
+ * at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
12
+ * string will cut short at that byte index.
13
+ * @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.
14
+ * @return {string}
15
+ */
16
+ function UTF8ToString(ptr: number, maxBytesToRead?: number | undefined, ignoreNul?: boolean | undefined): string;
17
+ function lengthBytesUTF8(str: any): number;
18
+ function stringToUTF8(str: any, outPtr: any, maxBytesToWrite: any): any;
19
+ let HEAPU8: any;
20
+ let FS_createPath: any;
21
+ function FS_createDataFile(parent: any, name: any, fileData: any, canRead: any, canWrite: any, canOwn: any): void;
22
+ function FS_preloadFile(parent: any, name: any, url: any, canRead: any, canWrite: any, dontCreateFile: any, canOwn: any, preFinish: any): Promise<void>;
23
+ function FS_unlink(path: any): any;
24
+ function addRunDependency(id: any): void;
25
+ function removeRunDependency(id: any): void;
26
+ }
27
+ interface WasmModule {
28
+ _malloc(_0: number): number;
29
+ _free(_0: number): void;
30
+ }
31
+
32
+ type EmbindString = ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string;
33
+ export interface ClassHandle {
34
+ isAliasOf(other: ClassHandle): boolean;
35
+ delete(): void;
36
+ deleteLater(): this;
37
+ isDeleted(): boolean;
38
+ // @ts-ignore - If targeting lower than ESNext, this symbol might not exist.
39
+ [Symbol.dispose](): void;
40
+ clone(): this;
41
+ }
42
+ export interface LogicalType extends ClassHandle {
43
+ isIntegral(): boolean;
44
+ isFloating(): boolean;
45
+ isNumeric(): boolean;
46
+ isTemporal(): boolean;
47
+ isValid(): boolean;
48
+ isComplete(): boolean;
49
+ isSigned(): boolean;
50
+ isUnsigned(): boolean;
51
+ hasAlias(): boolean;
52
+ id(): number;
53
+ physicalType(): number;
54
+ stringify(): string;
55
+ setAlias(_0: EmbindString): void;
56
+ getAlias(): string;
57
+ }
58
+
59
+ export interface Value extends ClassHandle {
60
+ type(): LogicalType;
61
+ copy(): Value;
62
+ isNull(): boolean;
63
+ getBoolean(): boolean;
64
+ getInt32(): number;
65
+ getFloat(): number;
66
+ getDouble(): number;
67
+ stringify(): string;
68
+ toSQLString(): string;
69
+ getString(): string;
70
+ }
71
+
72
+ export interface ErrorData extends ClassHandle {
73
+ hasError(): boolean;
74
+ message(): string;
75
+ rawMessage(): string;
76
+ }
77
+
78
+ export interface BaseQueryResult extends ClassHandle {
79
+ setError(_0: ErrorData): void;
80
+ hasError(): boolean;
81
+ resultType(): number;
82
+ statementType(): number;
83
+ columnCount(): bigint;
84
+ columnCount(): bigint;
85
+ throwError(_0: EmbindString): void;
86
+ getError(): string;
87
+ columnNames(): any;
88
+ columnTypes(): any;
89
+ }
90
+
91
+ export interface QueryResult extends BaseQueryResult {
92
+ print(): void;
93
+ stringify(): string;
94
+ columnName(_0: bigint): string;
95
+ }
96
+
97
+ export interface ColumnDataCollection extends ClassHandle {
98
+ count(): bigint;
99
+ columnCount(): bigint;
100
+ }
101
+
102
+ export interface MaterializedQueryResult extends QueryResult {
103
+ collection(): ColumnDataCollection;
104
+ rowCount(): bigint;
105
+ toJSON(): string;
106
+ getValue(_0: number, _1: number): any;
107
+ }
108
+
109
+ export interface PreparedStatement extends ClassHandle {
110
+ hasError(): boolean;
111
+ statementType(): number;
112
+ columnCount(): bigint;
113
+ getError(): string;
114
+ execute(_0: any): QueryResult | null;
115
+ names(): any;
116
+ types(): any;
117
+ }
118
+
119
+ export interface Connection extends ClassHandle {
120
+ interrupt(): void;
121
+ beginTransaction(): void;
122
+ commit(): void;
123
+ rollback(): void;
124
+ setAutoCommit(_0: boolean): void;
125
+ isAutoCommit(): boolean;
126
+ hasActiveTransaction(): boolean;
127
+ getQueryProgress(): number;
128
+ prepare(_0: EmbindString): PreparedStatement | null;
129
+ query(_0: EmbindString): MaterializedQueryResult | null;
130
+ queryToJSON(_0: EmbindString): string;
131
+ }
132
+
133
+ export interface DuckDB extends ClassHandle {
134
+ connect(): Connection | null;
135
+ terminate(): void;
136
+ numberOfThreads(): bigint;
137
+ }
138
+
139
+ interface EmbindModule {
140
+ LogicalType: {
141
+ new(): LogicalType;
142
+ };
143
+ Value: {
144
+ new(): Value;
145
+ };
146
+ ErrorData: {
147
+ new(): ErrorData;
148
+ };
149
+ BaseQueryResult: {};
150
+ QueryResult: {};
151
+ ColumnDataCollection: {};
152
+ MaterializedQueryResult: {};
153
+ PreparedStatement: {};
154
+ Connection: {};
155
+ DuckDB: {
156
+ standardVectorSize(): number;
157
+ sourceID(): string;
158
+ libraryVersion(): string;
159
+ releaseCodename(): string;
160
+ platform(): string;
161
+ };
162
+ create(): DuckDB | null;
163
+ standardVectorSize(): number;
164
+ libraryVersion(): string;
165
+ sourceID(): string;
166
+ releaseCodename(): string;
167
+ platform(): string;
168
+ }
169
+
170
+ export type MainModule = WasmModule & typeof RuntimeExports & EmbindModule;
171
+ export default function MainModuleFactory (options?: unknown): Promise<MainModule>;