@hpcc-js/wasm-duckdb 1.0.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 ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@hpcc-js/wasm-duckdb",
3
+ "version": "1.0.0",
4
+ "description": "hpcc-js - WASM DuckDB",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./types/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "types": "./types/index.d.ts",
13
+ "files": [
14
+ "dist/**/*",
15
+ "src/**/*",
16
+ "types/**/*"
17
+ ],
18
+ "scripts": {
19
+ "clean": "rimraf ./build ./dist ./dist-test ./types",
20
+ "pack-duckdb-eh-worker-node": "npx -y mkdirp build && node ./utils/sfx-wasm.js ../../node_modules/@duckdb/duckdb-wasm/dist/duckdb-node-eh.worker.cjs > ./build/duckdb-node-eh.worker.ts",
21
+ "pack-duckdb-eh-worker": "npx -y mkdirp build && node ./utils/sfx-wasm.js ../../node_modules/@duckdb/duckdb-wasm/dist/duckdb-browser-eh.worker.js > ./build/duckdb-browser-eh.worker.ts",
22
+ "pack-duckdb-eh": "npx -y mkdirp build && node ./utils/sfx-wasm.js ../../node_modules/@duckdb/duckdb-wasm/dist/duckdb-eh.wasm > ./build/duckdb-eh.wasm.ts",
23
+ "pack-duckdb": "run-p pack-duckdb-eh pack-duckdb-eh-worker pack-duckdb-eh-worker-node",
24
+ "build-types": "tsc --project tsconfig.json --emitDeclarationOnly",
25
+ "build-types-watch": "npm run build-types -- --watch",
26
+ "build-ts": "node esbuild.mjs",
27
+ "build-ts-dev": "npm run build-ts -- --mode=development",
28
+ "build-ts-watch": "npm run compile-ts-dev -- --watch",
29
+ "build-dev": "run-p build-types build-ts-dev",
30
+ "build": "npm-run-all --serial pack-duckdb --parallel build-types build-ts",
31
+ "lint-skypack": "npx -y @skypack/package-check",
32
+ "lint-eslint": "eslint src/**/*.ts",
33
+ "lint": "run-p lint-eslint lint-skypack",
34
+ "test-chrome": "karma start --single-run --browsers ChromiumHeadless karma.conf.cjs",
35
+ "test-firefox": "karma start --single-run --browsers Firefox karma.conf.cjs",
36
+ "test": "run-s test-chrome"
37
+ },
38
+ "dependencies": {
39
+ "yargs": "17.7.2"
40
+ },
41
+ "devDependencies": {
42
+ "@duckdb/duckdb-wasm": "1.28.1-dev106.0",
43
+ "@hpcc-js/esbuild-plugins": "1.0.0",
44
+ "npm-run-all": "4.1.5"
45
+ },
46
+ "keywords": [
47
+ "graphviz",
48
+ "typescript",
49
+ "webassembly",
50
+ "wasm",
51
+ "dot",
52
+ "neato",
53
+ "twopi"
54
+ ],
55
+ "author": "hpcc-systems",
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://github.com/hpcc-systems/hpcc-js-wasm.git"
59
+ },
60
+ "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
61
+ "license": "Apache-2.0"
62
+ }
package/src/duckdb.ts ADDED
@@ -0,0 +1,83 @@
1
+ // @ts-ignore
2
+ import load, { reset } from "../build/duckdb-eh.wasm.js";
3
+ // @ts-ignore
4
+ import loadWasmWorker, { reset as resetWasmWorker } from "../build/duckdb-browser-eh.worker.js";
5
+ import { AsyncDuckDB, ConsoleLogger } from "@duckdb/duckdb-wasm";
6
+
7
+ /**
8
+ * DuckDB WASM library, a in-process SQL OLAP Database Management System..
9
+ *
10
+ * See [DuckDB](https://github.com/duckdb/duckdb) for more details.
11
+ *
12
+ * ```ts
13
+ * import { DuckDB } from "@hpcc-js/wasm/duckdb";
14
+ *
15
+ * let duckdb = await DuckDB.load();
16
+ * const c = await duckdb.db.connect();
17
+ *
18
+ * const data = [
19
+ * { "col1": 1, "col2": "foo" },
20
+ * { "col1": 2, "col2": "bar" },
21
+ * ];
22
+ * await duckdb.db.registerFileText("rows.json", JSON.stringify(data));
23
+ * await c.insertJSONFromPath('rows.json', { name: 'rows' });
24
+ *
25
+ * const arrowResult = await c.query("SELECT * FROM read_json_auto('rows.json')");
26
+ * const result = arrowResult.toArray().map((row) => row.toJSON());
27
+ * expect(result.length).to.equal(data.length);
28
+ * for (let i = 0; i < result.length; i++) {
29
+ * expect(result[i].col2).to.equal(data[i].col2);
30
+ * }
31
+ *
32
+ * c.close();
33
+ * ```
34
+ */
35
+ export class DuckDB {
36
+
37
+ db: AsyncDuckDB;
38
+
39
+ private constructor(db: AsyncDuckDB, protected _version: string) {
40
+ this.db = db;
41
+ }
42
+
43
+ /**
44
+ * Compiles and instantiates the raw wasm.
45
+ *
46
+ * ::: info
47
+ * In general WebAssembly compilation is disallowed on the main thread if the buffer size is larger than 4KB, hence forcing `load` to be asynchronous;
48
+ * :::
49
+ *
50
+ * @returns A promise to an instance of the DuckDB class.
51
+ */
52
+ static load(): Promise<DuckDB> {
53
+ const workerUrl = URL.createObjectURL(
54
+ new Blob([loadWasmWorker()], { type: "text/javascript" })
55
+ );
56
+ const worker = new Worker(workerUrl);
57
+ URL.revokeObjectURL(workerUrl);
58
+ const logger = new ConsoleLogger();
59
+ const db = new AsyncDuckDB(logger, worker);
60
+ const wasmUrl = URL.createObjectURL(
61
+ new Blob([load()], { "type": "application/wasm" })
62
+ );
63
+ return db.instantiate(wasmUrl, null).then(async () => {
64
+ URL.revokeObjectURL(wasmUrl);
65
+ return new DuckDB(db, await db.getVersion());
66
+ });
67
+ }
68
+
69
+ /**
70
+ * Unloades the compiled wasm instance.
71
+ */
72
+ static unload() {
73
+ resetWasmWorker();
74
+ reset();
75
+ }
76
+
77
+ /**
78
+ * @returns The DuckDB version
79
+ */
80
+ version(): string {
81
+ return this._version;
82
+ }
83
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./duckdb.ts";
@@ -0,0 +1,52 @@
1
+ import { AsyncDuckDB } from "@duckdb/duckdb-wasm";
2
+ /**
3
+ * DuckDB WASM library, a in-process SQL OLAP Database Management System..
4
+ *
5
+ * See [DuckDB](https://github.com/duckdb/duckdb) for more details.
6
+ *
7
+ * ```ts
8
+ * import { DuckDB } from "@hpcc-js/wasm/duckdb";
9
+ *
10
+ * let duckdb = await DuckDB.load();
11
+ * const c = await duckdb.db.connect();
12
+ *
13
+ * const data = [
14
+ * { "col1": 1, "col2": "foo" },
15
+ * { "col1": 2, "col2": "bar" },
16
+ * ];
17
+ * await duckdb.db.registerFileText("rows.json", JSON.stringify(data));
18
+ * await c.insertJSONFromPath('rows.json', { name: 'rows' });
19
+ *
20
+ * const arrowResult = await c.query("SELECT * FROM read_json_auto('rows.json')");
21
+ * const result = arrowResult.toArray().map((row) => row.toJSON());
22
+ * expect(result.length).to.equal(data.length);
23
+ * for (let i = 0; i < result.length; i++) {
24
+ * expect(result[i].col2).to.equal(data[i].col2);
25
+ * }
26
+ *
27
+ * c.close();
28
+ * ```
29
+ */
30
+ export declare class DuckDB {
31
+ protected _version: string;
32
+ db: AsyncDuckDB;
33
+ private constructor();
34
+ /**
35
+ * Compiles and instantiates the raw wasm.
36
+ *
37
+ * ::: info
38
+ * In general WebAssembly compilation is disallowed on the main thread if the buffer size is larger than 4KB, hence forcing `load` to be asynchronous;
39
+ * :::
40
+ *
41
+ * @returns A promise to an instance of the DuckDB class.
42
+ */
43
+ static load(): Promise<DuckDB>;
44
+ /**
45
+ * Unloades the compiled wasm instance.
46
+ */
47
+ static unload(): void;
48
+ /**
49
+ * @returns The DuckDB version
50
+ */
51
+ version(): string;
52
+ }
@@ -0,0 +1 @@
1
+ export * from "./duckdb.ts";