matrix_sdk_indexeddb/media_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 crate::{
16 media_store::{
17 serializer::indexed_types::{IndexedMediaContentId, IndexedMediaContentSize},
18 types::UnixTime,
19 },
20 serializer::indexed_type::constants::{
21 INDEXED_KEY_LOWER_UUID, INDEXED_KEY_UPPER_DURATION_SECONDS, INDEXED_KEY_UPPER_UUID,
22 },
23};
24
25/// An [`IndexedMediaContentSize`] set to it's minimal value - i.e., `0`.
26///
27/// This value is useful for constructing a key range over all keys which
28/// contain [`IndexedMediaContentSize`] values when used in conjunction with
29/// [`INDEXED_KEY_UPPER_MEDIA_CONTENT_SIZE`].
30pub const INDEXED_KEY_LOWER_MEDIA_CONTENT_SIZE: IndexedMediaContentSize = 0;
31
32/// An [`IndexedMediaContentSize`] set to [`js_sys::Number::MAX_SAFE_INTEGER`].
33/// Note that this restricts the size of [`IndexedMedia::content`], which
34/// ultimately restricts the size of [`Media::content`].
35///
36/// This value is useful for constructing a key range over all keys which
37/// contain [`IndexedMediaContentSize`] values when used in conjunction with
38/// [`INDEXED_KEY_LOWER_MEDIA_CONTENT_SIZE`].
39pub const INDEXED_KEY_UPPER_MEDIA_CONTENT_SIZE: IndexedMediaContentSize =
40 js_sys::Number::MAX_SAFE_INTEGER as usize;
41
42/// The earliest [`UnixTime`] which can be represented in IndexedDB.
43///
44/// This value is useful for constructing a key range over all keys which
45/// contain time-related values when used in conjunction with
46/// [`INDEXED_KEY_UPPER_UNIX_TIME`].
47pub const INDEXED_KEY_LOWER_UNIX_TIME: UnixTime =
48 UnixTime::BeforeEpoch(INDEXED_KEY_UPPER_DURATION_SECONDS);
49
50/// The latest [`UnixTime`] which can be represented in IndexedDB.
51///
52/// This value is useful for constructing a key range over all keys which
53/// contain time-related values when used in conjunction with
54/// [`INDEXED_KEY_LOWER_UNIX_TIME`].
55pub const INDEXED_KEY_UPPER_UNIX_TIME: UnixTime =
56 UnixTime::AfterEpoch(INDEXED_KEY_UPPER_DURATION_SECONDS);
57
58/// The minimum value for an [`IndexedMediaContentId`] - i.e.,
59/// [`INDEXED_KEY_LOWER_UUID`].
60///
61/// This value is useful for constructing a key range over all keys which
62/// contain [`IndexedMediaContentId`] values when used in conjunction with
63/// [`INDEXED_KEY_UPPER_MEDIA_CONTENT_ID`].
64pub const INDEXED_KEY_LOWER_MEDIA_CONTENT_ID: IndexedMediaContentId = INDEXED_KEY_LOWER_UUID;
65
66/// The maximum value for an [`IndexedMediaContentId`] - i.e.,
67/// [`INDEXED_KEY_UPPER_UUID`].
68///
69/// This value is useful for constructing a key range over all keys which
70/// contain [`IndexedMediaContentId`] values when used in conjunction with
71/// [`INDEXED_KEY_LOWER_MEDIA_CONTENT_ID`].
72pub const INDEXED_KEY_UPPER_MEDIA_CONTENT_ID: IndexedMediaContentId = INDEXED_KEY_UPPER_UUID;