-
Notifications
You must be signed in to change notification settings - Fork 376
IndexedDB: Add (de)serialization functionality for EventCacheStore backend
#5226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Hywan
merged 10 commits into
matrix-org:main
from
mgoldenberg:indexeddb-event-cache-store-serializer
Jun 19, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9a50e0e
refactor(indexeddb): add trait for converting between high-level type…
mgoldenberg f74259b
refactor(indexeddb): add trait for encoding keys for indexed types in…
mgoldenberg 27c6967
refactor(indexeddb): add trait for constructing key bounds for indexe…
mgoldenberg 805a52e
refactor(indexeddb): expose current version and keys used in event ca…
mgoldenberg f9f467b
refactor(indexeddb): add indexing trait impls for chunk
mgoldenberg 52800bc
refactor(indexeddb): add indexing trait impls for event
mgoldenberg b1a969a
refactor(indexeddb): add chunk identifier into gap type
mgoldenberg e709481
refactor(indexeddb): add indexing trait impls for gap
mgoldenberg d3eecd3
refactor(indexeddb): add convenience functions for (de)serializing `I…
mgoldenberg 7d8c185
docs(indexeddb): add license to event_cache_store::types file
mgoldenberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
crates/matrix-sdk-indexeddb/src/event_cache_store/serializer/traits.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Copyright 2025 The Matrix.org Foundation C.I.C. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License | ||
|
|
||
| use ruma::RoomId; | ||
|
|
||
| use crate::serializer::IndexeddbSerializer; | ||
|
|
||
| /// A conversion trait for preparing high-level types into indexed types | ||
| /// which are better suited for storage in IndexedDB. | ||
| /// | ||
| /// Note that the functions below take an [`IndexeddbSerializer`] as an | ||
| /// argument, which provides the necessary context for encryption and | ||
| /// decryption, in the case the high-level type must be encrypted before | ||
| /// storage. | ||
| pub trait Indexed: Sized { | ||
| /// The indexed type that is used for storage in IndexedDB. | ||
| type IndexedType; | ||
| /// The error type that is returned when conversion fails. | ||
| type Error; | ||
|
|
||
| /// Converts the high-level type into an indexed type. | ||
| fn to_indexed( | ||
| &self, | ||
| room_id: &RoomId, | ||
| serializer: &IndexeddbSerializer, | ||
| ) -> Result<Self::IndexedType, Self::Error>; | ||
|
|
||
| /// Converts an indexed type into the high-level type. | ||
| fn from_indexed( | ||
| indexed: Self::IndexedType, | ||
| serializer: &IndexeddbSerializer, | ||
| ) -> Result<Self, Self::Error>; | ||
| } | ||
|
|
||
| /// A trait for encoding types which will be used as keys in IndexedDB. | ||
| /// | ||
| /// Each implementation represents a key on an [`Indexed`] type. | ||
| pub trait IndexedKey<T: Indexed> { | ||
| /// Any extra data used to construct the key. | ||
| type KeyComponents; | ||
|
|
||
| /// Encodes the key components into a type that can be used as a key in | ||
| /// IndexedDB. | ||
| /// | ||
| /// Note that this function takes an [`IndexeddbSerializer`] as an | ||
| /// argument, which provides the necessary context for encryption and | ||
| /// decryption, in the case that certain components of the key must be | ||
| /// encrypted before storage. | ||
| fn encode( | ||
| room_id: &RoomId, | ||
| components: &Self::KeyComponents, | ||
| serializer: &IndexeddbSerializer, | ||
| ) -> Self; | ||
| } | ||
|
|
||
| /// A trait for constructing the bounds of an [`IndexedKey`]. | ||
| /// | ||
| /// This is useful when constructing range queries in IndexedDB. | ||
| pub trait IndexedKeyBounds<T: Indexed>: IndexedKey<T> { | ||
| /// Encodes the lower bound of the key. | ||
| fn encode_lower(room_id: &RoomId, serializer: &IndexeddbSerializer) -> Self; | ||
|
|
||
| /// Encodes the upper bound of the key. | ||
| fn encode_upper(room_id: &RoomId, serializer: &IndexeddbSerializer) -> Self; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.