mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-08 10:44:20 +01:00
Cleanup logging, move html files
General cleanup of cruft, deleted dead code, moved html files to clean up dir.
This commit is contained in:
9
bindings/wasm/html/index.html
Normal file
9
bindings/wasm/html/index.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<script type="module">
|
||||
import { VFSInterface } from './src/opfs-interface.js';
|
||||
window.VFSInterface = VFSInterface;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,82 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<script type="module">
|
||||
import { VFSInterface } from './src/opfs-interface.js';
|
||||
window.VFSInterface = VFSInterface;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<!-- <!DOCTYPE html> -->
|
||||
<!-- <html> -->
|
||||
<!-- <head> -->
|
||||
<!-- <title>OPFS Tests</title> -->
|
||||
<!-- <style> -->
|
||||
<!-- .status-box { -->
|
||||
<!-- width: 100px; -->
|
||||
<!-- height: 100px; -->
|
||||
<!-- margin: 20px; -->
|
||||
<!-- border: 2px solid #333; -->
|
||||
<!-- } -->
|
||||
<!-- .success { background-color: #4CAF50; } -->
|
||||
<!-- .error { background-color: #f44336; } -->
|
||||
<!-- .running { background-color: #FFA500; } -->
|
||||
<!-- </style> -->
|
||||
<!-- </head> -->
|
||||
<!-- <body> -->
|
||||
<!-- <h1>OPFS Tests</h1> -->
|
||||
<!-- <button id="startTests">Run Tests</button> -->
|
||||
<!-- <div id="status" class="status-box"></div> -->
|
||||
<!-- <div id="results"></div> -->
|
||||
<!---->
|
||||
<!-- <script type="module"> -->
|
||||
<!-- import { VFSInterface } from './src/opfs-interface.js'; -->
|
||||
<!-- -->
|
||||
<!-- const status = document.getElementById('status'); -->
|
||||
<!-- const results = document.getElementById('results'); -->
|
||||
<!-- -->
|
||||
<!-- async function runTests() { -->
|
||||
<!-- status.className = 'status-box running'; -->
|
||||
<!-- results.innerHTML = ''; -->
|
||||
<!-- -->
|
||||
<!-- const log = (msg) => { -->
|
||||
<!-- console.log(msg); -->
|
||||
<!-- results.innerHTML += `<p>${msg}</p>`; -->
|
||||
<!-- }; -->
|
||||
<!---->
|
||||
<!-- try { -->
|
||||
<!-- const vfs = new VFSInterface("./src/opfs-worker.js"); -->
|
||||
<!-- -->
|
||||
<!-- log('Test 1: Basic Write/Read'); -->
|
||||
<!-- const testFd = await vfs.open('test.txt'); -->
|
||||
<!-- const writeData = new Uint8Array([1, 2, 3, 4]); -->
|
||||
<!-- const bytesWritten = await vfs.pwrite(testFd, writeData, 0); -->
|
||||
<!-- log(`Wrote ${bytesWritten} bytes`); -->
|
||||
<!---->
|
||||
<!-- const readBuffer = new Uint8Array(4); -->
|
||||
<!-- const bytesRead = await vfs.pread(testFd, readBuffer, 0); -->
|
||||
<!-- log(`Read ${bytesRead} bytes: ${Array.from(readBuffer)}`); -->
|
||||
<!-- -->
|
||||
<!-- log('Test 2: File Size'); -->
|
||||
<!-- const size = await vfs.size(testFd); -->
|
||||
<!-- log(`File size: ${size} bytes`); -->
|
||||
<!-- -->
|
||||
<!-- log('Test 3: Close File'); -->
|
||||
<!-- await vfs.close(testFd); -->
|
||||
<!-- log('File closed successfully'); -->
|
||||
<!---->
|
||||
<!-- status.className = 'status-box success'; -->
|
||||
<!---->
|
||||
<!-- } catch (error) { -->
|
||||
<!-- log(`Error: ${error.message}`); -->
|
||||
<!-- console.error('Full error:', error); -->
|
||||
<!-- status.className = 'status-box error'; -->
|
||||
<!-- } -->
|
||||
<!-- console.log("done and exiting"); -->
|
||||
<!-- } -->
|
||||
<!---->
|
||||
<!-- document.getElementById('startTests').onclick = () => runTests().catch(console.error); -->
|
||||
<!-- </script> -->
|
||||
<!-- </body> -->
|
||||
<!-- </html> -->
|
||||
@@ -48,7 +48,6 @@ impl Database {
|
||||
#[wasm_bindgen]
|
||||
pub fn exec(&self, _sql: &str) {
|
||||
let _res = self.conn.execute(_sql).unwrap();
|
||||
// Statement::new(RefCell::new(stmt), false)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# get target as argument from cli, defaults to nodejs if no argument is supplied
|
||||
TARGET=${1:-nodejs}
|
||||
FEATURE="nodejs"
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ initAll().then(() => {
|
||||
break;
|
||||
}
|
||||
case "exec": {
|
||||
console.log(e.data.sql);
|
||||
log(e.data.sql);
|
||||
db.exec(e.data.sql);
|
||||
self.postMessage({ type: "success", op: "exec" });
|
||||
break;
|
||||
@@ -53,3 +53,22 @@ initAll().then(() => {
|
||||
self.postMessage({ type: "error", error: error.toString() });
|
||||
});
|
||||
|
||||
// logLevel:
|
||||
//
|
||||
// 0 = no logging output
|
||||
// 1 = only errors
|
||||
// 2 = warnings and errors
|
||||
// 3 = debug, warnings, and errors
|
||||
const logLevel = 1;
|
||||
|
||||
const loggers = {
|
||||
0: console.error.bind(console),
|
||||
1: console.warn.bind(console),
|
||||
2: console.log.bind(console),
|
||||
};
|
||||
const logImpl = (level, ...args) => {
|
||||
if (logLevel > level) loggers[level]("OPFS asyncer:", ...args);
|
||||
};
|
||||
const log = (...args) => logImpl(2, ...args);
|
||||
const warn = (...args) => logImpl(1, ...args);
|
||||
const error = (...args) => logImpl(0, ...args);
|
||||
|
||||
@@ -8,9 +8,9 @@ let nextFd = 1;
|
||||
self.postMessage("ready");
|
||||
|
||||
onmessage = async (e) => {
|
||||
console.log("handle message: ", e.data);
|
||||
log("handle message: ", e.data);
|
||||
if (e.data.cmd === "init") {
|
||||
console.log("init");
|
||||
log("init");
|
||||
transferBuffer = e.data.transferBuffer;
|
||||
statusBuffer = e.data.statusBuffer;
|
||||
|
||||
@@ -33,7 +33,7 @@ self.onerror = (error) => {
|
||||
};
|
||||
|
||||
function handleCommand(msg) {
|
||||
console.log(`handle message: ${msg.cmd}`);
|
||||
log(`handle message: ${msg.cmd}`);
|
||||
switch (msg.cmd) {
|
||||
case "open":
|
||||
return handleOpen(msg.path);
|
||||
@@ -74,10 +74,10 @@ function handleRead(fd, offset, size) {
|
||||
const handle = handles.get(fd);
|
||||
const readBuffer = new ArrayBuffer(size);
|
||||
const readSize = handle.read(readBuffer, { at: offset });
|
||||
console.log("opfssync read: size: ", readBuffer.byteLength);
|
||||
log("opfssync read: size: ", readBuffer.byteLength);
|
||||
|
||||
const tmp = new Uint8Array(readBuffer);
|
||||
console.log("opfssync read buffer: ", [...tmp]);
|
||||
log("opfssync read buffer: ", [...tmp]);
|
||||
|
||||
transferArray.set(tmp);
|
||||
|
||||
@@ -85,8 +85,8 @@ function handleRead(fd, offset, size) {
|
||||
}
|
||||
|
||||
function handleWrite(fd, buffer, offset) {
|
||||
console.log("opfssync buffer size:", buffer.byteLength);
|
||||
console.log("opfssync write buffer: ", [...buffer]);
|
||||
log("opfssync buffer size:", buffer.byteLength);
|
||||
log("opfssync write buffer: ", [...buffer]);
|
||||
const handle = handles.get(fd);
|
||||
const size = handle.write(buffer, { at: offset });
|
||||
return { success: true, length: size };
|
||||
@@ -107,10 +107,30 @@ function sendResult(result) {
|
||||
if (result?.fd) {
|
||||
statusView.setInt32(4, result.fd, true);
|
||||
} else {
|
||||
console.log("opfs-sync-proxy: result.length: ", result.length);
|
||||
log("opfs-sync-proxy: result.length: ", result.length);
|
||||
statusView.setInt32(4, result?.length || 0, true);
|
||||
}
|
||||
|
||||
Atomics.store(statusArray, 0, 1);
|
||||
Atomics.notify(statusArray, 0);
|
||||
}
|
||||
|
||||
// logLevel:
|
||||
//
|
||||
// 0 = no logging output
|
||||
// 1 = only errors
|
||||
// 2 = warnings and errors
|
||||
// 3 = debug, warnings, and errors
|
||||
const logLevel = 1;
|
||||
|
||||
const loggers = {
|
||||
0: console.error.bind(console),
|
||||
1: console.warn.bind(console),
|
||||
2: console.log.bind(console),
|
||||
};
|
||||
const logImpl = (level, ...args) => {
|
||||
if (logLevel > level) loggers[level]("OPFS asyncer:", ...args);
|
||||
};
|
||||
const log = (...args) => logImpl(2, ...args);
|
||||
const warn = (...args) => logImpl(1, ...args);
|
||||
const error = (...args) => logImpl(0, ...args);
|
||||
|
||||
@@ -55,47 +55,3 @@ onmessage = async function (e) {
|
||||
};
|
||||
|
||||
console.log("opfs-worker.js");
|
||||
// checkCompatibility();
|
||||
|
||||
// // In VFS class
|
||||
// this.worker.onerror = (error) => {
|
||||
// console.error("Worker stack:", error.error?.stack || error.message);
|
||||
// };
|
||||
|
||||
// checkCompatibility();
|
||||
//
|
||||
// async function checkCompatibility() {
|
||||
// console.log("begin check compatibility");
|
||||
// // OPFS API check
|
||||
// if (!("storage" in navigator && "getDirectory" in navigator.storage)) {
|
||||
// throw new Error("OPFS API not supported");
|
||||
// }
|
||||
//
|
||||
// // SharedArrayBuffer support check
|
||||
// if (typeof SharedArrayBuffer === "undefined") {
|
||||
// throw new Error("SharedArrayBuffer not supported");
|
||||
// }
|
||||
//
|
||||
// // Atomics API check
|
||||
// if (typeof Atomics === "undefined") {
|
||||
// throw new Error("Atomics API not supported");
|
||||
// }
|
||||
//
|
||||
// // Permission check for OPFS
|
||||
// try {
|
||||
// const root = await navigator.storage.getDirectory();
|
||||
// await root.getFileHandle("test.txt", { create: true });
|
||||
// } catch (e) {
|
||||
// console.log(e);
|
||||
// console.log("throwing OPFS permission Denied");
|
||||
// throw new Error("OPFS permission denied");
|
||||
// }
|
||||
//
|
||||
// // Cross-Origin-Isolation check for SharedArrayBuffer
|
||||
// if (!crossOriginIsolated) {
|
||||
// throw new Error("Cross-Origin-Isolation required for SharedArrayBuffer");
|
||||
// }
|
||||
//
|
||||
// console.log("done check compatibility");
|
||||
// return true;
|
||||
// }
|
||||
|
||||
@@ -32,7 +32,7 @@ class VFS {
|
||||
initWorker() {
|
||||
return new Promise((resolve) => {
|
||||
this.worker.addEventListener("message", (e) => {
|
||||
console.log("eventListener: ", e.data);
|
||||
log("eventListener: ", e.data);
|
||||
resolve();
|
||||
}, { once: true });
|
||||
|
||||
@@ -50,8 +50,8 @@ class VFS {
|
||||
Atomics.wait(this.statusArray, 0, 0);
|
||||
|
||||
const result = this.statusView.getInt32(4, true);
|
||||
console.log("opfs.js open result: ", result);
|
||||
console.log("opfs.js open result type: ", typeof result);
|
||||
log("opfs.js open result: ", result);
|
||||
log("opfs.js open result type: ", typeof result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ class VFS {
|
||||
new Uint8Array(this.transferBuffer, 0, readSize),
|
||||
bytesRead,
|
||||
);
|
||||
console.log("opfs pread buffer: ", [...buffer]);
|
||||
log("opfs pread buffer: ", [...buffer]);
|
||||
|
||||
bytesRead += readSize;
|
||||
if (readSize < chunkSize) break;
|
||||
@@ -96,7 +96,7 @@ class VFS {
|
||||
}
|
||||
|
||||
pwrite(fd, buffer, offset) {
|
||||
console.log("write buffer size: ", buffer.byteLength);
|
||||
log("write buffer size: ", buffer.byteLength);
|
||||
Atomics.store(this.statusArray, 0, 0);
|
||||
this.worker.postMessage({
|
||||
cmd: "write",
|
||||
@@ -106,7 +106,7 @@ class VFS {
|
||||
});
|
||||
|
||||
Atomics.wait(this.statusArray, 0, 0);
|
||||
console.log(
|
||||
log(
|
||||
"opfs pwrite length statusview: ",
|
||||
this.statusView.getInt32(4, true),
|
||||
);
|
||||
@@ -119,8 +119,8 @@ class VFS {
|
||||
Atomics.wait(this.statusArray, 0, 0);
|
||||
|
||||
const result = this.statusView.getInt32(4, true);
|
||||
console.log("opfs.js size result: ", result);
|
||||
console.log("opfs.js size result type: ", typeof result);
|
||||
log("opfs.js size result: ", result);
|
||||
log("opfs.js size result type: ", typeof result);
|
||||
return BigInt(result);
|
||||
}
|
||||
|
||||
@@ -131,4 +131,24 @@ class VFS {
|
||||
}
|
||||
}
|
||||
|
||||
// logLevel:
|
||||
//
|
||||
// 0 = no logging output
|
||||
// 1 = only errors
|
||||
// 2 = warnings and errors
|
||||
// 3 = debug, warnings, and errors
|
||||
const logLevel = 1;
|
||||
|
||||
const loggers = {
|
||||
0: console.error.bind(console),
|
||||
1: console.warn.bind(console),
|
||||
2: console.log.bind(console),
|
||||
};
|
||||
const logImpl = (level, ...args) => {
|
||||
if (logLevel > level) loggers[level]("OPFS asyncer:", ...args);
|
||||
};
|
||||
const log = (...args) => logImpl(2, ...args);
|
||||
const warn = (...args) => logImpl(1, ...args);
|
||||
const error = (...args) => logImpl(0, ...args);
|
||||
|
||||
export { VFS };
|
||||
|
||||
@@ -4,10 +4,7 @@ export class VFS {
|
||||
}
|
||||
|
||||
open(path, flags) {
|
||||
const result = self.vfs.open(path);
|
||||
consol.log("webvfs open result: ", result);
|
||||
consol.log("webvfs open result type: ", typeof result);
|
||||
return result;
|
||||
return self.vfs.open(path);
|
||||
}
|
||||
|
||||
close(fd) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach } from "vitest";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach } from "vitest";
|
||||
import { chromium } from "playwright";
|
||||
import { createServer } from "vite";
|
||||
|
||||
@@ -7,8 +7,7 @@ let context;
|
||||
let page;
|
||||
let server;
|
||||
|
||||
beforeEach(async () => {
|
||||
// Start Vite dev server
|
||||
beforeAll(async () => {
|
||||
server = await createServer({
|
||||
configFile: "./vite.config.js",
|
||||
root: ".",
|
||||
@@ -17,17 +16,20 @@ beforeEach(async () => {
|
||||
},
|
||||
});
|
||||
await server.listen();
|
||||
|
||||
browser = await chromium.launch();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
context = await browser.newContext();
|
||||
page = await context.newPage();
|
||||
|
||||
globalThis.__page__ = page;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await context.close();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await browser.close();
|
||||
await server.close();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<script type="module">
|
||||
import { VFSInterface } from './src/opfs-interface.js';
|
||||
|
||||
console.log('made it here')
|
||||
|
||||
window.runTest = async () => {
|
||||
console.log('made it here')
|
||||
const vfs = new VFSInterface(new URL('./src/opfs-worker.js', import.meta.url).href);
|
||||
console.log('made it here')
|
||||
|
||||
// Test file operations
|
||||
const fd = await vfs.open('test.txt', {});
|
||||
|
||||
// Write data
|
||||
const writeData = new Uint8Array([1, 2, 3, 4]);
|
||||
const bytesWritten = await vfs.pwrite(fd, writeData, 0);
|
||||
|
||||
// Read data
|
||||
const readData = new Uint8Array(4);
|
||||
const bytesRead = await vfs.pread(fd, readData, 0);
|
||||
|
||||
// Close file
|
||||
await vfs.close(fd);
|
||||
|
||||
return {
|
||||
bytesWritten,
|
||||
bytesRead,
|
||||
readData: Array.from(readData)
|
||||
};
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -2,6 +2,8 @@ import { defineConfig } from "vite";
|
||||
import wasm from "vite-plugin-wasm";
|
||||
|
||||
export default defineConfig({
|
||||
publicDir: "./html",
|
||||
root: ".",
|
||||
plugins: [wasm()],
|
||||
test: {
|
||||
globals: true,
|
||||
@@ -28,7 +30,4 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
},
|
||||
// worker: {
|
||||
// format: "es",
|
||||
// },
|
||||
});
|
||||
|
||||
@@ -35,7 +35,6 @@ use storage::sqlite3_ondisk::{DatabaseHeader, DATABASE_HEADER_SIZE};
|
||||
pub use storage::wal::WalFile;
|
||||
pub use storage::wal::WalFileShared;
|
||||
use util::parse_schema_rows;
|
||||
// use web_sys::console; // Add to dependencies in Cargo.toml
|
||||
|
||||
use translate::select::prepare_select_plan;
|
||||
use types::OwnedValue;
|
||||
@@ -81,8 +80,6 @@ impl Database {
|
||||
pub fn open_file(io: Arc<dyn IO>, path: &str) -> Result<Arc<Database>> {
|
||||
use storage::wal::WalFileShared;
|
||||
|
||||
// console::log_1(&"Hello from Rust!".into());
|
||||
|
||||
let file = io.open_file(path, io::OpenFlags::Create, true)?;
|
||||
maybe_init_database_file(&file, &io)?;
|
||||
let page_io = Rc::new(FileStorage::new(file));
|
||||
|
||||
Reference in New Issue
Block a user