Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ui/src/lib/demo/components/engine-panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
</div>
<table class="w-full text-left">
<tbody>
{#each snapshot.orders as order (order.order_id)}
<!-- Rows as the engine returns them: an order a build wrote twice shows twice. -->
{#each snapshot.orders as order, index (`${index}:${order.order_id}`)}
<tr><td>#{order.order_id}</td><td>{order.status}</td><td class="text-right">{dollars(order.total_cents)}</td></tr>
{/each}
</tbody>
Expand Down
21 changes: 17 additions & 4 deletions website/scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,23 @@ for (const [from, to] of Object.entries(redirects)) {
const ui = new URL('../ui/', root);
const chdb = new URL('node_modules/chdb-wasm/', root);
const { version: engineVersion } = JSON.parse(await readFile(new URL('package.json', chdb), 'utf8'));
// The parts are cached for good, so their path names the exact bytes: gzip output can differ
// between builds of the same version, and a half-cached old part must never join a new one.
// The engine's files are cached for good, so their path names the exact bytes: gzip output can
// differ between builds of the same version, and a half-cached old part must never join a new one.
const wasm = await readFile(new URL('dist/chdb.wasm', chdb));
const packed = gzipSync(wasm, { level: 9 });
const engineBase = `/demo/engine/${engineVersion}-${createHash('sha256').update(packed).digest('hex').slice(0, 12)}/`;
// The engine's worker hands Emscripten the downloaded wasm as bytes (wasmBinary), and Firefox then
// never finishes starting it; streaming the same blob URL starts in about a second in every browser.
const workerSource = await readFile(new URL('dist/worker.js', chdb), 'utf8');
const wasmAsBytes = ` const bytes = await fetchWithProgress(payload.wasmUrl, id);
if (bytes)
moduleOpts.wasmBinary = bytes;`;
if (!workerSource.includes(wasmAsBytes)) throw new Error(`chdb-wasm ${engineVersion}'s worker no longer loads the wasm as bytes; recheck the Firefox start.`);
const worker = workerSource.replace(
wasmAsBytes,
` moduleOpts.locateFile = (path, prefix) => (path.endsWith('.wasm') ? payload.wasmUrl : prefix + path);`,
);
const engineHash = createHash('sha256').update(packed).update(worker).digest('hex').slice(0, 12);
const engineBase = `/demo/engine/${engineVersion}-${engineHash}/`;
if (!existsSync(new URL('node_modules/', ui))) {
// The UI's lockfile needs the npm it pins, as `make ui-install` uses.
const { packageManager } = JSON.parse(await readFile(new URL('package.json', ui), 'utf8'));
Expand All @@ -44,9 +56,10 @@ await cp(new URL('build/', ui), demo, { recursive: true });
// at most 25 MiB, and the page joins and gunzips them.
const engine = new URL(engineBase.slice(1), output);
await mkdir(engine, { recursive: true });
for (const file of ['index.js', 'async.js', 'bindings.js', 'platform.js', 'protocol.js', 'status.js', 'worker.js', 'chdb.mjs']) {
for (const file of ['index.js', 'async.js', 'bindings.js', 'platform.js', 'protocol.js', 'status.js', 'chdb.mjs']) {
await copyFile(new URL(`dist/${file}`, chdb), new URL(file, engine));
}
await writeFile(new URL('worker.js', engine), worker);
await copyFile(new URL('LICENSE', chdb), new URL('LICENSE', engine));
const half = Math.ceil(packed.length / 2);
const parts = [packed.subarray(0, half), packed.subarray(half)];
Expand Down
2 changes: 2 additions & 0 deletions website/tests/ui-demo.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ test('on the real engine Execute, Promote and Roll back run, and every page read
});

test('without cross-origin isolation the demo says so and plays the recording', async ({ page }) => {
// Only the page's own headers decide isolation; other requests the page may drop mid-flight.
await page.route('**/demo/**', async (route) => {
if (route.request().resourceType() !== 'document') return route.continue();
const response = await route.fetch();
const headers = response.headers();
delete headers['cross-origin-embedder-policy'];
Expand Down
Loading