mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-25 20:14:21 +01:00
Merge 'Fix JavaScript bindings packaging' from Nikita Sivukhin
This PR configure `#entry-point` import alias for javascript bindings in
order to use `browser.js` napi-rs generated file in browser context.
Also, this PR forces napi-rs to emit `index.js` entrypoint using ESM and
also use typescript for writing our wrapper code around napi-rs
bindings.
In order to make behaviour consistent when lib is imported through ESM
or CommonJS this PR also replace default export of `Database` by named
on. The problem is that `export default Database` will be logically
equivalent to `modules.export.default = Database` which is not the same
thing as `modules.export = Database` and this will need to access
additional `.default` field with CommonJs style imports (e.g. `new
require('@tursodatabase/turso').default(...)`). In order to remove this
difference - I just replaced default export with named one.
Closes #2488
This commit is contained in:
@@ -34,8 +34,9 @@ enum PresentationMode {
|
||||
|
||||
/// A database connection.
|
||||
#[napi]
|
||||
#[derive(Clone)]
|
||||
pub struct Database {
|
||||
_db: Arc<turso_core::Database>,
|
||||
_db: Option<Arc<turso_core::Database>>,
|
||||
io: Arc<dyn turso_core::IO>,
|
||||
conn: Arc<turso_core::Connection>,
|
||||
is_memory: bool,
|
||||
@@ -76,13 +77,22 @@ impl Database {
|
||||
.connect()
|
||||
.map_err(|e| Error::new(Status::GenericFailure, format!("Failed to connect: {e}")))?;
|
||||
|
||||
Ok(Database {
|
||||
Ok(Self::create(Some(db), io, conn, is_memory))
|
||||
}
|
||||
|
||||
pub fn create(
|
||||
db: Option<Arc<turso_core::Database>>,
|
||||
io: Arc<dyn turso_core::IO>,
|
||||
conn: Arc<turso_core::Connection>,
|
||||
is_memory: bool,
|
||||
) -> Self {
|
||||
Database {
|
||||
_db: db,
|
||||
io,
|
||||
conn,
|
||||
is_memory,
|
||||
is_open: Cell::new(true),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns whether the database is in memory-only mode.
|
||||
@@ -418,7 +428,8 @@ impl Statement {
|
||||
|
||||
/// Async task for running the I/O loop.
|
||||
pub struct IoLoopTask {
|
||||
io: Arc<dyn turso_core::IO>,
|
||||
// this field is set in the turso-sync-engine package
|
||||
pub io: Arc<dyn turso_core::IO>,
|
||||
}
|
||||
|
||||
impl Task for IoLoopTask {
|
||||
|
||||
Reference in New Issue
Block a user