matrix_sdk_indexeddb/event_cache_store/serializer/constants.rs
1// Copyright 2025 The Matrix.org Foundation C.I.C.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License
14
15use std::sync::LazyLock;
16
17use matrix_sdk_base::linked_chunk::ChunkIdentifier;
18
19use crate::event_cache_store::types::Position;
20
21/// A [`ChunkIdentifier`] constructed with `0`.
22///
23/// This value is useful for constructing a key range over all keys which
24/// contain [`ChunkIdentifier`]s when used in conjunction with
25/// [`INDEXED_KEY_UPPER_CHUNK_IDENTIFIER`].
26pub static INDEXED_KEY_LOWER_CHUNK_IDENTIFIER: LazyLock<ChunkIdentifier> =
27 LazyLock::new(|| ChunkIdentifier::new(0));
28
29/// A [`ChunkIdentifier`] constructed with [`js_sys::Number::MAX_SAFE_INTEGER`].
30///
31/// This value is useful for constructing a key range over all keys which
32/// contain [`ChunkIdentifier`]s when used in conjunction with
33/// [`INDEXED_KEY_LOWER_CHUNK_IDENTIFIER`].
34pub static INDEXED_KEY_UPPER_CHUNK_IDENTIFIER: LazyLock<ChunkIdentifier> =
35 LazyLock::new(|| ChunkIdentifier::new(js_sys::Number::MAX_SAFE_INTEGER as u64));
36
37/// The lowest possible index that can be used to reference an [`Event`] inside
38/// a [`Chunk`] - i.e., `0`.
39///
40/// This value is useful for constructing a key range over all keys which
41/// contain [`Position`]s when used in conjunction with
42/// [`INDEXED_KEY_UPPER_EVENT_INDEX`].
43pub const INDEXED_KEY_LOWER_EVENT_INDEX: usize = 0;
44
45/// The highest possible index that can be used to reference an [`Event`] inside
46/// a [`Chunk`] - i.e., [`js_sys::Number::MAX_SAFE_INTEGER`].
47///
48/// This value is useful for constructing a key range over all keys which
49/// contain [`Position`]s when used in conjunction with
50/// [`INDEXED_KEY_LOWER_EVENT_INDEX`].
51pub const INDEXED_KEY_UPPER_EVENT_INDEX: usize = js_sys::Number::MAX_SAFE_INTEGER as usize;
52
53/// The lowest possible [`Position`] that can be used to reference an [`Event`].
54///
55/// This value is useful for constructing a key range over all keys which
56/// contain [`Position`]s when used in conjunction with
57/// [`INDEXED_KEY_UPPER_EVENT_INDEX`].
58pub static INDEXED_KEY_LOWER_EVENT_POSITION: LazyLock<Position> = LazyLock::new(|| Position {
59 chunk_identifier: INDEXED_KEY_LOWER_CHUNK_IDENTIFIER.index(),
60 index: INDEXED_KEY_LOWER_EVENT_INDEX,
61});
62
63/// The highest possible [`Position`] that can be used to reference an
64/// [`Event`].
65///
66/// This value is useful for constructing a key range over all keys which
67/// contain [`Position`]s when used in conjunction with
68/// [`INDEXED_KEY_LOWER_EVENT_INDEX`].
69pub static INDEXED_KEY_UPPER_EVENT_POSITION: LazyLock<Position> = LazyLock::new(|| Position {
70 chunk_identifier: INDEXED_KEY_UPPER_CHUNK_IDENTIFIER.index(),
71 index: INDEXED_KEY_UPPER_EVENT_INDEX,
72});