@uwdata/mosaic-duckdb 0.16.2 → 0.18.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  BSD 3-Clause License
2
2
 
3
- Copyright (c) 2023, UW Interactive Data Lab
3
+ Copyright (c) 2023-2025, UW Interactive Data Lab
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
6
6
  modification, are permitted provided that the following conditions are met:
package/README.md CHANGED
@@ -4,6 +4,6 @@
4
4
 
5
5
  A Promise-based Node.js API to DuckDB, along with a data server that supports transfer of [Apache Arrow](https://arrow.apache.org/) and JSON data over either Web Sockets or HTTP.
6
6
 
7
- _Warning_: Due to persistent quality issues involving the Node.js DuckDB client and Arrow extension, we recommend using the Python-based [`duckdb-server`](https://github.com/uwdata/mosaic/tree/main/packages/duckdb-server) package instead. However, we retain this package for both backwards compatibility and potential future use as quality issues improve.
7
+ _Warning_: Due to persistent quality issues involving the Node.js DuckDB client and Arrow extension, we recommend using the Python-based [`duckdb-server`](https://github.com/uwdata/mosaic/tree/main/packages/server/duckdb-server) package instead. However, we retain this package for both backwards compatibility and potential future use as quality issues improve.
8
8
 
9
- _Note:_ This package provides a local DuckDB server for Node.js. To instead use DuckDB-WASM in the browser, use the `wasmConnector` in the [`mosaic-core`](https://github.com/uwdata/mosaic/tree/main/packages/mosaic-core) package.
9
+ _Note:_ This package provides a local DuckDB server for Node.js. To instead use DuckDB-WASM in the browser, use the `wasmConnector` in the [`mosaic-core`](https://github.com/uwdata/mosaic/tree/main/packages/mosaic/mosaic-core) package.
@@ -0,0 +1,22 @@
1
+ export function cacheKey(hashable: any, type: any): string;
2
+ export class Cache {
3
+ constructor({ max, dir, ttl }: {
4
+ max?: number;
5
+ dir?: string;
6
+ ttl?: number;
7
+ });
8
+ cache: Map<any, any>;
9
+ max: number;
10
+ dir: string;
11
+ ttl: number;
12
+ has(key: any): boolean;
13
+ delete(key: any): boolean;
14
+ get(key: any): any;
15
+ set(key: any, data: any, { persist, ttl }?: {
16
+ persist?: boolean;
17
+ ttl?: number;
18
+ }): this;
19
+ shouldEvict(): boolean;
20
+ evict(): void;
21
+ }
22
+ //# sourceMappingURL=Cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../src/Cache.js"],"names":[],"mappings":"AAOA,2DAEC;AAaD;IACE;;;;OAUC;IALC,qBAAoB;IACpB,YAAc;IACd,YAAc;IACd,YAAc;IAIhB,uBAEC;IAED,0BAMC;IAED,mBAEC;IAED;;;aAMC;IAED,uBAEC;IAED,cAyBC;CACF"}
@@ -0,0 +1,21 @@
1
+ export class DuckDB {
2
+ constructor(path?: string, config?: {}, initStatements?: string);
3
+ db: duckdb.Database;
4
+ con: duckdb.Connection;
5
+ close(): Promise<any>;
6
+ prepare(sql: any): DuckDBStatement;
7
+ exec(sql: any): Promise<any>;
8
+ query(sql: any): Promise<any>;
9
+ arrowBuffer(sql: any): Promise<any>;
10
+ }
11
+ export class DuckDBStatement {
12
+ constructor(statement: any);
13
+ statement: any;
14
+ finalize(): void;
15
+ run(params: any): void;
16
+ exec(params: any): Promise<any>;
17
+ query(params: any): Promise<any>;
18
+ arrowBuffer(params: any): Promise<any>;
19
+ }
20
+ import duckdb from 'duckdb';
21
+ //# sourceMappingURL=DuckDB.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DuckDB.d.ts","sourceRoot":"","sources":["../../src/DuckDB.js"],"names":[],"mappings":"AAaA;IACE,iEAQC;IAHC,oBAA2C;IAC3C,uBAA4B;IAI9B,sBAUC;IAED,mCAEC;IAED,6BAUC;IAED,8BAUC;IAED,oCAUC;CACF;AAED;IACE,4BAEC;IADC,eAA0B;IAG5B,iBAEC;IAED,uBAEC;IAED,gCAUC;IAED,iCAUC;IAED,uCAUC;CACF;mBA7HkB,QAAQ"}
@@ -0,0 +1,15 @@
1
+ export function dataServer(db: any, { cache, rest, socket, port }?: {
2
+ cache?: boolean;
3
+ rest?: boolean;
4
+ socket?: boolean;
5
+ port?: number;
6
+ }): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
7
+ export function queryHandler(db: any, queryCache: any): (res: any, data: any) => Promise<void>;
8
+ export function socketResponse(ws: any): {
9
+ arrow(data: any): void;
10
+ json(data: any): void;
11
+ done(): void;
12
+ error(err: any): void;
13
+ };
14
+ import http from 'node:http';
15
+ //# sourceMappingURL=data-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-server.d.ts","sourceRoot":"","sources":["../../src/data-server.js"],"names":[],"mappings":"AAOA;;;;;yEAgBC;AA6CD,yDAqBgB,QAAG,EAAE,SAAI,mBAwCxB;AAwBD;;;;;EAmBC;iBA5KgB,WAAW"}
@@ -0,0 +1,8 @@
1
+ export { DuckDB } from "./DuckDB.js";
2
+ export { Cache } from "./Cache.js";
3
+ export { loadArrow } from "./load/arrow.js";
4
+ export { loadCSV } from "./load/csv.js";
5
+ export { loadJSON } from "./load/json.js";
6
+ export { loadParquet } from "./load/parquet.js";
7
+ export { dataServer, queryHandler, socketResponse } from "./data-server.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export function loadArrow(db: any, tableName: any, buffer: any): Promise<any>;
2
+ //# sourceMappingURL=arrow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrow.d.ts","sourceRoot":"","sources":["../../../src/load/arrow.js"],"names":[],"mappings":"AAEA,8EAWC"}
@@ -0,0 +1,2 @@
1
+ export function loadCSV(db: any, tableName: any, fileName: any, options?: {}): any;
2
+ //# sourceMappingURL=csv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv.d.ts","sourceRoot":"","sources":["../../../src/load/csv.js"],"names":[],"mappings":"AAEA,mFAEC"}
@@ -0,0 +1,2 @@
1
+ export function loadJSON(db: any, tableName: any, fileName: any, options?: {}): any;
2
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../src/load/json.js"],"names":[],"mappings":"AAEA,oFAEC"}
@@ -0,0 +1,2 @@
1
+ export function loadParquet(db: any, tableName: any, fileName: any, options?: {}): any;
2
+ //# sourceMappingURL=parquet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parquet.d.ts","sourceRoot":"","sources":["../../../src/load/parquet.js"],"names":[],"mappings":"AAEA,uFAEC"}
@@ -0,0 +1,2 @@
1
+ export function mergeBuffers(buffers: any): Uint8Array<any>;
2
+ //# sourceMappingURL=merge-buffers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-buffers.d.ts","sourceRoot":"","sources":["../../src/merge-buffers.js"],"names":[],"mappings":"AAAA,4DAYC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uwdata/mosaic-duckdb",
3
- "version": "0.16.2",
3
+ "version": "0.18.0",
4
4
  "description": "A Promise-based DuckDB API and Node.js data server.",
5
5
  "keywords": [
6
6
  "duckdb",
@@ -13,8 +13,15 @@
13
13
  "author": "Jeffrey Heer (https://idl.uw.edu)",
14
14
  "type": "module",
15
15
  "exports": {
16
+ "types": "./dist/src/index.d.ts",
16
17
  "default": "./src/index.js"
17
18
  },
19
+ "files": [
20
+ "bin",
21
+ "dist",
22
+ "!dist/tsconfig.tsbuildinfo",
23
+ "src"
24
+ ],
18
25
  "repository": {
19
26
  "type": "git",
20
27
  "url": "https://github.com/uwdata/mosaic.git"
@@ -25,15 +32,16 @@
25
32
  "to-parquet": "./bin/to-parquet.js"
26
33
  },
27
34
  "scripts": {
35
+ "clean": "rimraf dist && mkdir dist",
28
36
  "lint": "eslint src test",
29
37
  "server": "node bin/run-server.js",
30
38
  "test": "vitest run",
31
- "prepublishOnly": "npm run test && npm run lint"
39
+ "prepublishOnly": "npm run test && npm run lint && tsc --build"
32
40
  },
33
41
  "dependencies": {
34
- "@uwdata/mosaic-sql": "^0.16.2",
35
- "duckdb": "^1.2.1",
42
+ "@uwdata/mosaic-sql": "^0.18.0",
43
+ "duckdb": "~1.2.1",
36
44
  "ws": "^8.18.2"
37
45
  },
38
- "gitHead": "26d2719f4bcab471d2831145e1f03f39f3509869"
46
+ "gitHead": "dfb9ded0b0307754e3185ca34cc49a1384fe8455"
39
47
  }
package/src/Cache.js CHANGED
@@ -93,7 +93,7 @@ async function readEntries(dir, cache) {
93
93
  let files;
94
94
  try {
95
95
  files = await fs.readdir(dir);
96
- } catch (err) { // eslint-disable-line no-unused-vars
96
+ } catch (err) {
97
97
  return; // dir does not exist, nothing to do
98
98
  }
99
99
  await Promise.allSettled(files.map(async file => {
@@ -1,12 +1,9 @@
1
1
  import http from 'node:http';
2
- import path from 'node:path';
3
2
  import url from 'node:url';
4
3
  import { WebSocketServer } from 'ws';
5
4
  import { Cache, cacheKey } from './Cache.js';
6
- import { createBundle, loadBundle } from './load/bundle.js';
7
5
 
8
6
  const CACHE_DIR = '.mosaic/cache';
9
- const BUNDLE_DIR = '.mosaic/bundle';
10
7
 
11
8
  export function dataServer(db, {
12
9
  cache = true,
@@ -121,19 +118,6 @@ export function queryHandler(db, queryCache) {
121
118
  // JSON response format
122
119
  res.json(await retrieve(query, sql => db.query(sql)));
123
120
  break;
124
- case 'create-bundle':
125
- // Create a named bundle of precomputed resources
126
- await createBundle(
127
- db, queryCache, query.queries,
128
- path.resolve(BUNDLE_DIR, query.name)
129
- );
130
- res.done();
131
- break;
132
- case 'load-bundle':
133
- // Load a named bundle of precomputed resources
134
- await loadBundle(db, queryCache, path.resolve(BUNDLE_DIR, query.name));
135
- res.done();
136
- break;
137
121
  default:
138
122
  res.error(`Unrecognized command: ${type}`, 400);
139
123
  }
@@ -1,75 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { cacheKey } from '../Cache.js';
4
-
5
- async function retrieve(db, cache, sql, type) {
6
- const key = cacheKey(sql, type);
7
- const cached = cache.get(key);
8
- if (cached) return cached;
9
- switch (type) {
10
- case 'arrow':
11
- return db.arrowBuffer(sql);
12
- case 'json':
13
- return JSON.stringify(await db.query(sql));
14
- default:
15
- throw new Error(`Unsupported query type: ${type}`);
16
- }
17
- }
18
-
19
- export async function createBundle(db, cache, queries, dir) {
20
- const describe_re = /^DESCRIBE /;
21
- const pragma_re = /^PRAGMA /;
22
- const view_re = /^CREATE( TEMP| TEMPORARY)? VIEW/;
23
- const table_re = /^CREATE( TEMP| TEMPORARY)? TABLE( IF NOT EXISTS)? ([^\s]+)/;
24
-
25
- const manifest = { tables: [], queries: [] };
26
-
27
- await fs.mkdir(dir, { recursive: true });
28
-
29
- const querySet = new Set(queries);
30
- for (const query of querySet) {
31
- const sql = typeof query === 'string' ? query : query.sql;
32
- if (query.alias) {
33
- const table = query.alias;
34
- const file = path.resolve(dir, `${table}.parquet`);
35
- await db.exec(`COPY (${sql}) TO '${file}' (FORMAT PARQUET)`);
36
- manifest.tables.push(table);
37
- } else if (sql.startsWith('CREATE ')) {
38
- // table or view
39
- if (view_re.test(sql)) continue; // ignore views
40
- const table = sql.match(table_re)?.[3];
41
- const file = path.resolve(dir, `${table}.parquet`);
42
- await db.exec(`${sql}`);
43
- await db.exec(`COPY ${table} TO '${file}' (FORMAT PARQUET)`);
44
- manifest.tables.push(table);
45
- } else if (!pragma_re.test(sql)) {
46
- // select query
47
- const type = describe_re.test(sql) ? 'json' : 'arrow';
48
- const key = cacheKey(sql, type);
49
- const result = await retrieve(db, cache, sql, type);
50
- await fs.writeFile(path.resolve(dir, key), result);
51
- manifest.queries.push(key);
52
- }
53
- }
54
-
55
- await fs.writeFile(path.resolve(dir, 'bundle.json'), JSON.stringify(manifest, 0, 2));
56
- return manifest;
57
- }
58
-
59
- export async function loadBundle(db, cache, dir) {
60
- const manifest = JSON.parse(await fs.readFile(path.resolve(dir, 'bundle.json')));
61
-
62
- // load precomputed query results into the cache
63
- for (const key of manifest.queries) {
64
- const file = path.resolve(dir, key);
65
- const json = path.extname(file) === '.json';
66
- const data = await fs.readFile(file);
67
- cache.set(key, json ? JSON.parse(data) : data);
68
- }
69
-
70
- // load precomputed tables into the database
71
- for (const table of manifest.tables) {
72
- const file = path.resolve(dir, `${table}.parquet`);
73
- await db.exec(`CREATE TABLE IF NOT EXISTS ${table} AS SELECT * FROM '${file}'`);
74
- }
75
- }
package/vitest.config.ts DELETED
@@ -1,3 +0,0 @@
1
- import { defineConfig } from 'vite';
2
-
3
- export default defineConfig({});