Skip to content
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ use seshat::{Database, Event, Profile};
use tempfile::tempdir;

let tmpdir = tempdir().unwrap();
let mut db = Database::new(tmpdir.path()).unwrap();
let db = Database::new(tmpdir.path()).unwrap();

/// Method to call for every live event that gets received during a sync.
fn add_live_event(event: Event, profile: Profile, database: &Database) {
database.add_event(event, profile);
}
/// Method to call on every successful sync after live events were added.
fn on_sync(database: &mut Database) {
fn on_sync(database: &Database) {
database.commit().unwrap();
}
```
Expand Down
56 changes: 21 additions & 35 deletions seshat-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ impl SeshatRecovery {
Ok(c) => match c {
Ok(c) => c,
Err(e) => {
return cx.throw_type_error(format!(
"Unable to get a database connection {}",
e.to_string()
))
return cx
.throw_type_error(format!("Unable to get a database connection {}", e))
}
},
Err(e) => return cx.throw_type_error(e),
Expand Down Expand Up @@ -191,10 +189,8 @@ impl Seshat {
Ok(c) => match c {
Ok(c) => c,
Err(e) => {
return cx.throw_type_error(format!(
"Unable to get a database connection {}",
e.to_string()
))
return cx
.throw_type_error(format!("Unable to get a database connection {}", e))
}
},
Err(e) => return cx.throw_type_error(e),
Expand Down Expand Up @@ -267,8 +263,8 @@ impl Seshat {
};

let receiver = {
let db = &mut this.borrow_mut().database;
db.as_mut().map_or_else(
let db = &this.borrow().database;
db.as_ref().map_or_else(
|| Err(CLOSED_ERROR),
|db| {
if force {
Expand Down Expand Up @@ -324,10 +320,8 @@ impl Seshat {
Ok(c) => match c {
Ok(c) => c,
Err(e) => {
return cx.throw_type_error(format!(
"Unable to get a database connection {}",
e.to_string()
))
return cx
.throw_type_error(format!("Unable to get a database connection {}", e))
}
},
Err(e) => return cx.throw_type_error(e),
Expand Down Expand Up @@ -369,10 +363,8 @@ impl Seshat {
Ok(c) => match c {
Ok(c) => c,
Err(e) => {
return cx.throw_type_error(format!(
"Unable to get a database connection {}",
e.to_string()
))
return cx
.throw_type_error(format!("Unable to get a database connection {}", e))
}
},
Err(e) => return cx.throw_type_error(e),
Expand All @@ -397,10 +389,8 @@ impl Seshat {
Ok(c) => match c {
Ok(c) => c,
Err(e) => {
return cx.throw_type_error(format!(
"Unable to get a database connection {}",
e.to_string()
))
return cx
.throw_type_error(format!("Unable to get a database connection {}", e))
}
},
Err(e) => return cx.throw_type_error(e),
Expand All @@ -427,10 +417,8 @@ impl Seshat {
Ok(c) => match c {
Ok(c) => c,
Err(e) => {
return cx.throw_type_error(format!(
"Unable to get a database connection {}",
e.to_string()
))
return cx
.throw_type_error(format!("Unable to get a database connection {}", e))
}
},
Err(e) => return cx.throw_type_error(e),
Expand All @@ -455,10 +443,8 @@ impl Seshat {
Ok(c) => match c {
Ok(c) => c,
Err(e) => {
return cx.throw_type_error(format!(
"Unable to get a database connection {}",
e.to_string()
))
return cx
.throw_type_error(format!("Unable to get a database connection {}", e))
}
},
Err(e) => return cx.throw_type_error(e),
Expand Down Expand Up @@ -491,10 +477,10 @@ impl Seshat {
};

let ret = {
let db = &mut this.borrow_mut().database;
let db = &this.borrow().database;

if wait {
db.as_mut().map_or_else(
db.as_ref().map_or_else(
|| Err(CLOSED_ERROR),
|db| {
if force {
Expand All @@ -505,7 +491,7 @@ impl Seshat {
},
)
} else {
db.as_mut().map_or_else(
db.as_ref().map_or_else(
|| Err(CLOSED_ERROR),
|db| {
db.commit_no_wait();
Expand Down Expand Up @@ -585,7 +571,7 @@ impl Seshat {

let searcher = match searcher {
Ok(s) => s,
Err(e) => return cx.throw_type_error(e.to_string()),
Err(e) => return cx.throw_type_error(e),
};

let task = SearchTask {
Expand Down Expand Up @@ -697,7 +683,7 @@ impl Seshat {
Ok(s) => s,
Err(e) => return cx.throw_type_error(e.to_string()),
},
Err(e) => return cx.throw_type_error(e.to_string()),
Err(e) => return cx.throw_type_error(e),
};

let task = LoadFileEventsTask {
Expand Down
19 changes: 5 additions & 14 deletions seshat-node/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Task for CommitTask {
) -> JsResult<'a, Self::JsEvent> {
match result {
Ok(_) => Ok(cx.undefined()),
Err(e) => cx.throw_error(format!("Error writing to database: {}", e.to_string())),
Err(e) => cx.throw_error(format!("Error writing to database: {}", e)),
}
}
}
Expand Down Expand Up @@ -503,7 +503,7 @@ impl Task for DeleteEventTask {
) -> JsResult<'a, Self::JsEvent> {
match result {
Ok(b) => Ok(cx.boolean(b)),
Err(e) => cx.throw_error(format!("Error deleting an event: {}", e.to_string())),
Err(e) => cx.throw_error(format!("Error deleting an event: {}", e)),
}
}
}
Expand Down Expand Up @@ -535,10 +535,7 @@ impl Task for ChangePassphraseTask {
) -> JsResult<'a, Self::JsEvent> {
match result {
Ok(_) => Ok(cx.undefined()),
Err(e) => cx.throw_error(format!(
"Error while changing the passphrase: {}",
e.to_string()
)),
Err(e) => cx.throw_error(format!("Error while changing the passphrase: {}", e)),
}
}
}
Expand Down Expand Up @@ -566,10 +563,7 @@ impl Task for GetUserVersionTask {
let version = cx.number(version as f64);
Ok(version)
}
Err(e) => cx.throw_error(format!(
"Error while getting the user version: {}",
e.to_string()
)),
Err(e) => cx.throw_error(format!("Error while getting the user version: {}", e)),
}
}
}
Expand All @@ -595,10 +589,7 @@ impl Task for SetUserVersionTask {
) -> JsResult<'a, Self::JsEvent> {
match result {
Ok(_) => Ok(cx.undefined()),
Err(e) => cx.throw_error(format!(
"Error while setting the user version: {}",
e.to_string()
)),
Err(e) => cx.throw_error(format!("Error while setting the user version: {}", e)),
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions seshat-node/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ pub(crate) fn deserialize_event<'a, C: Context<'a>>(
let source: serde_json::Value = match source {
Ok(s) => s,
Err(e) => {
return cx.throw_type_error(format!(
"Couldn't load the event from the store: {}",
e.to_string()
))
return cx.throw_type_error(format!("Couldn't load the event from the store: {}", e))
}
};

Expand Down Expand Up @@ -372,7 +369,7 @@ pub(crate) fn parse_event(
"m.room.message" => EventType::Message,
"m.room.name" => EventType::Name,
"m.room.topic" => EventType::Topic,
e => return cx.throw_type_error(format!("Unsupported event type {e}")),
e => return cx.throw_type_error(format!("Unsupported event type {}", e)),
};

let key = match event_type {
Expand Down
2 changes: 1 addition & 1 deletion seshat-node/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ describe('Database', function() {
it('should not barf on nul bytes in the event', async function() {
const db = createDb();
const events = [{event: nulByteEvent, profile: matrixProfileOnlyDisplayName}];
db.addHistoricEvents(events);
await db.addHistoricEvents(events);
await db.commit(true);
db.reload();
});
Expand Down
Loading