Skip to content

Commit 26f3526

Browse files
committed
Update indexed_db crate to fe645fae2a91a48a0af6126611c2031d59db0ad1 (i.e. to-be-merged PR Ekleog/indexed-db#12)
1 parent fed6ef3 commit 26f3526

File tree

8 files changed

+45
-62
lines changed

8 files changed

+45
-62
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ glob = { version = "0.3.2", default-features = false }
144144
gloo-timers = { version = "0.3.0", default-features = false }
145145
hex = { version = "0.4.3", default-features = false }
146146
hex-literal = { version = "0.4.1", default-features = false }
147-
# Base on https://github.com/Ekleog/indexed-db/pull/9
148-
indexed-db = { git = "https://github.com/Ekleog/indexed-db.git", rev = "d92f17e0e2cd48abc4b2d2adf62ccef9a9924080", default-features = false }
147+
# Based on https://github.com/Ekleog/indexed-db/pull/12
148+
indexed-db = { git = "https://github.com/Ekleog/indexed-db.git", rev = "fe645fae2a91a48a0af6126611c2031d59db0ad1", default-features = false }
149149
# indexed-db = { path = "../indexed-db/", version = "0.4.2", default-features = false }
150150
itertools = { version = "0.12.1", default-features = false }
151151
jni = { version = "0.21.1", default-features = false }

libparsec/crates/platform_storage/src/testbed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ mod drop_existing_web_indexed_db {
4444
use super::*;
4545

4646
async fn drop_db(name: &str) {
47-
indexed_db::Factory::<()>::get()
47+
indexed_db::Factory::get()
4848
.unwrap()
4949
.delete_database(name)
5050
.await

libparsec/crates/platform_storage/src/web/certificates.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS
22

3-
use std::collections::HashMap;
43
use std::path::Path;
4+
use std::{collections::HashMap, convert::Infallible};
55
use wasm_bindgen::{JsCast, JsValue};
66

77
use indexed_db::{Database, Factory, Transaction};
@@ -48,9 +48,9 @@ const INDEX_FILTER2: &'static str = "_idx_filter2";
4848
const INDEX_FILTERS: &'static str = "_idx_filters";
4949

5050
async fn initialize_database(
51-
db: &Database<CustomErrMarker>,
52-
) -> indexed_db::Result<(), CustomErrMarker> {
53-
let store = db.build_object_store(STORE).auto_increment().create()?;
51+
evt: &indexed_db::VersionChangeEvent<Infallible>,
52+
) -> indexed_db::Result<(), Infallible> {
53+
let store = evt.build_object_store(STORE).auto_increment().create()?;
5454

5555
store
5656
.build_compound_index(
@@ -745,7 +745,7 @@ async fn debug_dump(transaction: &Transaction<CustomErrMarker>) -> anyhow::Resul
745745

746746
#[derive(Debug)]
747747
pub(crate) struct PlatformCertificatesStorage {
748-
conn: Database<CustomErrMarker>,
748+
conn: Database,
749749
}
750750

751751
// SAFETY: see `pretend_future_is_send_on_web`'s documentation for the full explanation.
@@ -772,18 +772,13 @@ impl PlatformCertificatesStorage {
772772

773773
let name = get_certificates_storage_db_name(data_base_dir, device.device_id);
774774

775-
let factory = Factory::<CustomErrMarker>::get()?;
775+
let factory = Factory::get()?;
776776
let conn = factory
777-
.open(
778-
&name,
779-
DB_VERSION,
780-
|evt: indexed_db::VersionChangeEvent<CustomErrMarker>| async move {
781-
// 2) Initialize the database (if needed)
782-
783-
let db = evt.database();
784-
initialize_database(&db).await
785-
},
786-
)
777+
.open(&name, DB_VERSION, async |evt| {
778+
// 2) Initialize the database (if needed)
779+
780+
initialize_database(&evt).await
781+
})
787782
.await?;
788783

789784
// 3) All done !

libparsec/crates/platform_storage/src/web/cleanup.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ use std::path::Path;
44

55
use libparsec_types::{anyhow, DeviceID};
66

7-
use super::{
8-
certificates::get_certificates_storage_db_name, user::get_user_storage_db_name,
9-
utils::CustomErrMarker,
10-
};
7+
use super::{certificates::get_certificates_storage_db_name, user::get_user_storage_db_name};
118

129
async fn drop_db(name: &str) -> anyhow::Result<()> {
13-
indexed_db::Factory::<CustomErrMarker>::get()
10+
indexed_db::Factory::get()
1411
.map_err(anyhow::Error::from)?
1512
.delete_database(name)
1613
.await

libparsec/crates/platform_storage/src/web/user.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS
22

3-
use std::path::Path;
3+
use std::{convert::Infallible, path::Path};
44

55
use indexed_db::{Database, Factory, ObjectStore, Transaction};
66
use libparsec_types::prelude::*;
@@ -30,16 +30,16 @@ const SINGLETON_NEED_SYNC_FIELD: &str = "need_sync";
3030
const SINGLETON_BLOB_FIELD: &str = "blob";
3131

3232
async fn initialize_database(
33-
db: &Database<CustomErrMarker>,
34-
) -> indexed_db::Result<(), CustomErrMarker> {
35-
db.build_object_store(STORE).create()?;
33+
evt: &indexed_db::VersionChangeEvent<Infallible>,
34+
) -> indexed_db::Result<(), Infallible> {
35+
evt.build_object_store(STORE).create()?;
3636

3737
Ok(())
3838
}
3939

4040
#[derive(Debug)]
4141
pub struct PlatformUserStorage {
42-
conn: Database<CustomErrMarker>,
42+
conn: Database,
4343
#[cfg(any(test, feature = "expose-test-methods"))]
4444
realm_id: VlobID,
4545
}
@@ -68,18 +68,13 @@ impl PlatformUserStorage {
6868

6969
let name = get_user_storage_db_name(data_base_dir, device.device_id);
7070

71-
let factory = Factory::<CustomErrMarker>::get().map_err(|e| anyhow::anyhow!("{e:?}"))?;
71+
let factory = Factory::get().map_err(|e| anyhow::anyhow!("{e:?}"))?;
7272
let conn = factory
73-
.open(
74-
&name,
75-
DB_VERSION,
76-
|evt: indexed_db::VersionChangeEvent<CustomErrMarker>| async move {
77-
// 2) Initialize the database (if needed)
78-
79-
let db = evt.database();
80-
initialize_database(&db).await
81-
},
82-
)
73+
.open(&name, DB_VERSION, async |evt| {
74+
// 2) Initialize the database (if needed)
75+
76+
initialize_database(&evt).await
77+
})
8378
.await?;
8479

8580
// 3) All done !

libparsec/crates/platform_storage/src/web/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub(super) use with_transaction;
186186
// However this is not yet possible since for the moment `indexed_db` API requires
187187
// a single error type for all operations (see https://github.com/Ekleog/indexed-db/issues/4).
188188
pub(super) async fn with_transaction_internal<R, E>(
189-
conn: &Database<CustomErrMarker>,
189+
conn: &Database,
190190
stores: &[&str],
191191
rw: bool,
192192
cb: impl AsyncFnOnce(Transaction<CustomErrMarker>) -> Result<R, E>,

libparsec/crates/platform_storage/src/web/workspace.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS
22

3+
use std::convert::Infallible;
34
use std::path::Path;
45

56
use indexed_db::{Database, Factory, ObjectStore, Transaction};
@@ -82,16 +83,15 @@ const BLOCKS_ACCESSED_ON_FIELD: &str = "accessed_on";
8283
const BLOCKS_DATA_FIELD: &str = "data";
8384

8485
async fn initialize_database(
85-
evt: &indexed_db::VersionChangeEvent<CustomErrMarker>,
86-
) -> indexed_db::Result<(), CustomErrMarker> {
87-
let db = evt.database();
88-
86+
evt: &indexed_db::VersionChangeEvent<Infallible>,
87+
) -> indexed_db::Result<(), Infallible> {
8988
// 1) Create the stores
9089

91-
db.build_object_store(PREVENT_SYNC_PATTERN_STORE).create()?;
92-
db.build_object_store(CHECKPOINT_STORE).create()?;
90+
evt.build_object_store(PREVENT_SYNC_PATTERN_STORE)
91+
.create()?;
92+
evt.build_object_store(CHECKPOINT_STORE).create()?;
9393

94-
let vlob_store = db.build_object_store(VLOBS_STORE).create()?;
94+
let vlob_store = evt.build_object_store(VLOBS_STORE).create()?;
9595
vlob_store
9696
.build_index(VLOBS_INDEX_INBOUND_NEED_SYNC, VLOBS_INBOUND_NEED_SYNC_FIELD)
9797
.create()?;
@@ -102,9 +102,9 @@ async fn initialize_database(
102102
)
103103
.create()?;
104104

105-
db.build_object_store(CHUNKS_STORE).create()?;
105+
evt.build_object_store(CHUNKS_STORE).create()?;
106106

107-
let block_store = db.build_object_store(BLOCKS_STORE).create()?;
107+
let block_store = evt.build_object_store(BLOCKS_STORE).create()?;
108108
block_store
109109
.build_index(BLOCKS_INDEX_ACCESSED_ON, BLOCKS_ACCESSED_ON_FIELD)
110110
.create()?;
@@ -140,7 +140,7 @@ async fn initialize_database(
140140

141141
#[derive(Debug)]
142142
pub struct PlatformWorkspaceStorage {
143-
conn: Database<CustomErrMarker>,
143+
conn: Database,
144144
max_blocks: u64,
145145
}
146146

@@ -171,17 +171,13 @@ impl PlatformWorkspaceStorage {
171171

172172
let name = get_workspace_storage_db_name(data_base_dir, device.device_id, realm_id);
173173

174-
let factory = Factory::<CustomErrMarker>::get().map_err(|e| anyhow::anyhow!("{e:?}"))?;
174+
let factory = Factory::get().map_err(|e| anyhow::anyhow!("{e:?}"))?;
175175
let conn = factory
176-
.open(
177-
&name,
178-
DB_VERSION,
179-
|evt: indexed_db::VersionChangeEvent<CustomErrMarker>| async move {
180-
// 2) Initialize the database (if needed)
181-
182-
initialize_database(&evt).await
183-
},
184-
)
176+
.open(&name, DB_VERSION, async |evt| {
177+
// 2) Initialize the database (if needed)
178+
179+
initialize_database(&evt).await
180+
})
185181
.await?;
186182

187183
// 3) All done !

0 commit comments

Comments
 (0)