chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
|
||||
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
|
||||
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
|
||||
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
|
||||
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
|
||||
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
|
||||
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
|
||||
// ┃ This file is part of the Perspective library, distributed under the terms ┃
|
||||
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
|
||||
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
||||
|
||||
import esbuild from "esbuild";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { dirname } from "path";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
async function build() {
|
||||
await esbuild.build({
|
||||
entryPoints: ["src/index.ts"],
|
||||
outdir: "dist",
|
||||
format: "esm",
|
||||
bundle: true,
|
||||
sourcemap: "inline",
|
||||
target: "es2022",
|
||||
loader: {
|
||||
".ttf": "file",
|
||||
".wasm": "file",
|
||||
".arrow": "file",
|
||||
},
|
||||
assetNames: "[name]",
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, "dist/index.html"),
|
||||
fs.readFileSync(path.join(__dirname, "src/index.html")).toString(),
|
||||
);
|
||||
}
|
||||
|
||||
build();
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "esbuild-duckdb-virtual",
|
||||
"private": true,
|
||||
"version": "4.5.2",
|
||||
"type": "module",
|
||||
"description": "Example of a custom VirtualServer running in a Web Worker",
|
||||
"scripts": {
|
||||
"build": "node build.js",
|
||||
"start": "node build.js && node server.mjs"
|
||||
},
|
||||
"keywords": [],
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@perspective-dev/client": "workspace:^",
|
||||
"@perspective-dev/server": "workspace:^",
|
||||
"@perspective-dev/viewer": "workspace:^",
|
||||
"@perspective-dev/viewer-charts": "workspace:^",
|
||||
"@perspective-dev/viewer-datagrid": "workspace:^",
|
||||
"@duckdb/duckdb-wasm": "catalog:",
|
||||
"superstore-arrow": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"esbuild": "catalog:"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
|
||||
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
|
||||
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
|
||||
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
|
||||
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
|
||||
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
|
||||
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
|
||||
// ┃ This file is part of the Perspective library, distributed under the terms ┃
|
||||
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
|
||||
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
||||
|
||||
// This is just a file server, the implementation is in `src/index.js`.
|
||||
|
||||
import http from "http";
|
||||
import { fileURLToPath } from "url";
|
||||
import { dirname } from "path";
|
||||
import { cwd_static_file_handler } from "@perspective-dev/client";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
// Create HTTP server for serving static files
|
||||
const httpServer = http.createServer((req, res) =>
|
||||
cwd_static_file_handler(req, res, [`${__dirname}/dist`, __dirname]),
|
||||
);
|
||||
|
||||
httpServer.listen(8080, () => {
|
||||
console.log("Server listening on http://localhost:8080");
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Web Worker VirtualServer Example</title>
|
||||
<script type="module" src="index.js"></script>
|
||||
<link rel="stylesheet" href="index.css" />
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
}
|
||||
perspective-viewer {
|
||||
flex: 1;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<perspective-viewer></perspective-viewer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,87 @@
|
||||
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
|
||||
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
|
||||
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
|
||||
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
|
||||
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
|
||||
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
|
||||
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
|
||||
// ┃ This file is part of the Perspective library, distributed under the terms ┃
|
||||
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
|
||||
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
||||
|
||||
import perspective from "@perspective-dev/client";
|
||||
import perspective_viewer from "@perspective-dev/viewer";
|
||||
import "@perspective-dev/viewer-datagrid";
|
||||
import "@perspective-dev/viewer-charts";
|
||||
|
||||
import "@perspective-dev/viewer/dist/css/themes.css";
|
||||
import "@perspective-dev/viewer/dist/css/pro.css";
|
||||
|
||||
// @ts-ignore
|
||||
import SERVER_WASM from "@perspective-dev/server/dist/wasm/perspective-server.wasm";
|
||||
|
||||
// @ts-ignore
|
||||
import CLIENT_WASM from "@perspective-dev/viewer/dist/wasm/perspective-viewer.wasm";
|
||||
|
||||
import { DuckDBHandler } from "@perspective-dev/client/dist/esm/virtual_servers/duckdb.js";
|
||||
import * as duckdb from "@duckdb/duckdb-wasm";
|
||||
|
||||
// @ts-ignore
|
||||
import SUPERSTORE_ARROW from "superstore-arrow/superstore.lz4.arrow";
|
||||
|
||||
await Promise.all([
|
||||
// @ts-ignore
|
||||
perspective.init_server(fetch(SERVER_WASM)),
|
||||
// @ts-ignore
|
||||
perspective_viewer.init_client(fetch(CLIENT_WASM)),
|
||||
]);
|
||||
|
||||
async function initializeDuckDB() {
|
||||
const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();
|
||||
const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES);
|
||||
const worker_url = URL.createObjectURL(
|
||||
new Blob([`importScripts("${bundle.mainWorker}");`], {
|
||||
type: "text/javascript",
|
||||
}),
|
||||
);
|
||||
|
||||
const duckdb_worker = new Worker(worker_url);
|
||||
const logger = new duckdb.VoidLogger();
|
||||
const db = new duckdb.AsyncDuckDB(logger, duckdb_worker);
|
||||
await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
|
||||
URL.revokeObjectURL(worker_url);
|
||||
const conn = await db.connect();
|
||||
await conn.query(`
|
||||
SET default_null_order=NULLS_FIRST_ON_ASC_LAST_ON_DESC;
|
||||
`);
|
||||
|
||||
console.log("DuckDB initialized");
|
||||
return conn;
|
||||
}
|
||||
|
||||
async function loadSampleData(db: duckdb.AsyncDuckDBConnection) {
|
||||
try {
|
||||
const response = await fetch(SUPERSTORE_ARROW);
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
await db.insertArrowFromIPCStream(new Uint8Array(arrayBuffer), {
|
||||
name: "data_source_one",
|
||||
create: true,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error loading Arrow data:", error);
|
||||
}
|
||||
}
|
||||
|
||||
const db = await initializeDuckDB();
|
||||
await perspective.init_client(fetch(CLIENT_WASM));
|
||||
await loadSampleData(db);
|
||||
const server = perspective.createMessageHandler(new DuckDBHandler(db));
|
||||
const client = await perspective.worker(server);
|
||||
|
||||
const viewer = document.querySelector("perspective-viewer")!;
|
||||
viewer.load(client);
|
||||
viewer.restore({
|
||||
table: "memory.data_source_one",
|
||||
group_by: ["State"],
|
||||
});
|
||||
Reference in New Issue
Block a user