mirror of
https://github.com/h-sphere/sql-seal.git
synced 2026-07-22 10:10:28 +00:00
* feat: WIP. Proof of concept of using sqlite-wasm * chore: few experiments with kysely * chore: poc of using idb with modern version of sqlite * feat: reworking project to use wa-sqlite * feat: making database queries work too * infra: refactoring database connection and cleaning dependencies * fix: fixing issue with tests * chore: adding missing packages * chore: underlying engine updated to wa-sqlite
39 lines
1 KiB
JavaScript
39 lines
1 KiB
JavaScript
// Jest setup file for ESM mode
|
|
// Polyfill fetch to handle file:// URLs for wa-sqlite WASM loading
|
|
|
|
import { readFileSync } from 'fs';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const originalFetch = global.fetch;
|
|
|
|
global.fetch = async function (url, options) {
|
|
// Handle file:// URLs by reading from filesystem
|
|
if (typeof url === 'string' && url.startsWith('file://')) {
|
|
try {
|
|
const filePath = fileURLToPath(url);
|
|
const buffer = readFileSync(filePath);
|
|
|
|
// Return a proper Response object
|
|
return new Response(buffer, {
|
|
status: 200,
|
|
statusText: 'OK',
|
|
headers: {
|
|
'Content-Type': 'application/wasm',
|
|
'Content-Length': buffer.length.toString(),
|
|
},
|
|
});
|
|
} catch (error) {
|
|
return new Response(null, {
|
|
status: 404,
|
|
statusText: 'Not Found',
|
|
});
|
|
}
|
|
}
|
|
|
|
// Fall back to original fetch for http:// and https://
|
|
if (originalFetch) {
|
|
return originalFetch(url, options);
|
|
}
|
|
|
|
throw new Error('fetch is not available');
|
|
};
|