@@ -42,7 +42,7 @@ use crate::{
42
42
Indexed , IndexedKey , IndexedKeyBounds , IndexedKeyComponentBounds ,
43
43
IndexedPrefixKeyBounds , IndexedPrefixKeyComponentBounds ,
44
44
} ,
45
- types:: { Chunk , Event , Gap , Position } ,
45
+ types:: { Chunk , Event , Gap , Lease , Position } ,
46
46
} ,
47
47
serializer:: { IndexeddbSerializer , MaybeEncrypted } ,
48
48
} ;
@@ -65,6 +65,14 @@ const INDEXED_KEY_LOWER_CHARACTER: char = '\u{0000}';
65
65
/// [1]: https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane
66
66
const INDEXED_KEY_UPPER_CHARACTER : char = '\u{FFFF}' ;
67
67
68
+ /// Identical to [`INDEXED_KEY_LOWER_CHARACTER`] but represented as a [`String`]
69
+ static INDEXED_KEY_LOWER_STRING : LazyLock < String > =
70
+ LazyLock :: new ( || String :: from ( INDEXED_KEY_LOWER_CHARACTER ) ) ;
71
+
72
+ /// Identical to [`INDEXED_KEY_UPPER_CHARACTER`] but represented as a [`String`]
73
+ static INDEXED_KEY_UPPER_STRING : LazyLock < String > =
74
+ LazyLock :: new ( || String :: from ( INDEXED_KEY_UPPER_CHARACTER ) ) ;
75
+
68
76
/// A [`ChunkIdentifier`] constructed with `0`.
69
77
///
70
78
/// This value is useful for constructing a key range over all keys which
@@ -223,6 +231,70 @@ impl<K> From<K> for IndexedKeyRange<K> {
223
231
}
224
232
}
225
233
234
+ /// Represents the [`LEASES`][1] object store.
235
+ ///
236
+ /// [1]: crate::event_cache_store::migrations::v1::create_lease_object_store
237
+ #[ derive( Debug , Serialize , Deserialize ) ]
238
+ pub struct IndexedLease {
239
+ /// The primary key of the object store.
240
+ pub id : IndexedLeaseIdKey ,
241
+ /// The (possibly encrypted) content - i.e., a [`Lease`].
242
+ pub content : IndexedLeaseContent ,
243
+ }
244
+
245
+ impl Indexed for Lease {
246
+ type IndexedType = IndexedLease ;
247
+
248
+ const OBJECT_STORE : & ' static str = keys:: LEASES ;
249
+
250
+ type Error = CryptoStoreError ;
251
+
252
+ fn to_indexed (
253
+ & self ,
254
+ serializer : & IndexeddbSerializer ,
255
+ ) -> Result < Self :: IndexedType , Self :: Error > {
256
+ Ok ( IndexedLease {
257
+ id : IndexedLeaseIdKey :: encode ( & self . key , serializer) ,
258
+ content : serializer. maybe_encrypt_value ( self ) ?,
259
+ } )
260
+ }
261
+
262
+ fn from_indexed (
263
+ indexed : Self :: IndexedType ,
264
+ serializer : & IndexeddbSerializer ,
265
+ ) -> Result < Self , Self :: Error > {
266
+ serializer. maybe_decrypt_value ( indexed. content )
267
+ }
268
+ }
269
+
270
+ /// The value associated with the [primary key](IndexedLease::id) of the
271
+ /// [`LEASES`][1] object store, which is constructed from the value in
272
+ /// [`Lease::key`]. This value may or may not be hashed depending on the
273
+ /// provided [`IndexeddbSerializer`].
274
+ ///
275
+ /// [1]: crate::event_cache_store::migrations::v1::create_linked_chunks_object_store
276
+ pub type IndexedLeaseIdKey = String ;
277
+
278
+ impl IndexedKey < Lease > for IndexedLeaseIdKey {
279
+ type KeyComponents < ' a > = & ' a str ;
280
+
281
+ fn encode ( components : Self :: KeyComponents < ' _ > , serializer : & IndexeddbSerializer ) -> Self {
282
+ serializer. encode_key_as_string ( keys:: LEASES , components)
283
+ }
284
+ }
285
+
286
+ impl IndexedKeyComponentBounds < Lease > for IndexedLeaseIdKey {
287
+ fn lower_key_components ( ) -> Self :: KeyComponents < ' static > {
288
+ INDEXED_KEY_LOWER_STRING . as_str ( )
289
+ }
290
+
291
+ fn upper_key_components ( ) -> Self :: KeyComponents < ' static > {
292
+ INDEXED_KEY_UPPER_STRING . as_str ( )
293
+ }
294
+ }
295
+
296
+ pub type IndexedLeaseContent = MaybeEncrypted ;
297
+
226
298
/// Represents the [`LINKED_CHUNKS`][1] object store.
227
299
///
228
300
/// [1]: crate::event_cache_store::migrations::v1::create_linked_chunks_object_store
0 commit comments