icydb_core/
lib.rs

1//! Core runtime for IcyDB: entity traits, values, executors, visitors, and
2//! the ergonomics exported via the `prelude`.
3pub mod db;
4pub mod design;
5pub mod hash;
6pub mod index;
7pub mod interface;
8pub mod key;
9pub mod macros;
10pub mod obs;
11pub mod serialize;
12pub mod traits;
13pub mod types;
14pub mod value;
15pub mod view;
16pub mod visitor;
17
18pub use index::IndexSpec;
19pub use key::Key;
20pub use serialize::{deserialize, serialize};
21pub use value::Value;
22pub use visitor::{sanitize, validate};
23
24/// re-exports
25///
26/// macros can use these, stops the user having to specify all the dependencies
27/// in the Cargo.toml file manually
28///
29/// these have to be in icydb_core because of the base library not being able to import icydb
30pub mod __reexports {
31    pub use canic_core;
32    pub use canic_memory;
33    pub use ctor;
34    pub use derive_more;
35    pub use num_traits;
36    pub use remain;
37}
38
39///
40/// CONSTANTS
41///
42
43/// Maximum number of indexed fields allowed on an entity.
44///
45/// This limit keeps hashed index keys within bounded, storable sizes and
46/// simplifies sizing tests in the stores.
47pub const MAX_INDEX_FIELDS: usize = 4;
48
49///
50/// ICYDB ACTOR PRELUDE
51/// using _ brings traits into scope and avoids name conflicts
52///
53
54pub mod prelude {
55    pub use crate::{
56        db,
57        db::{
58            executor::SaveExecutor,
59            primitives::{
60                self, FilterDsl, FilterExpr, FilterExt as _, LimitExpr, LimitExt as _, SortExpr,
61                SortExt as _,
62            },
63            query,
64            response::Response,
65        },
66        key::Key,
67        traits::{
68            CreateView as _, EntityKind as _, FilterView as _, Inner as _, Path as _,
69            UpdateView as _, View as _,
70        },
71        types::*,
72        value::Value,
73        view::{Create, Filter, Update, View},
74    };
75    pub use candid::CandidType;
76    pub use serde::{Deserialize, Serialize};
77}
78
79use candid::CandidType;
80use serde::{Deserialize, Serialize};
81use thiserror::Error as ThisError;
82
83///
84/// Error
85///
86/// top level error should handle all sub-errors, but not expose the candid types
87/// as that would be a lot of them
88///
89
90#[derive(CandidType, Debug, Deserialize, Serialize, ThisError)]
91pub enum Error {
92    #[error("{0}")]
93    DbError(String),
94
95    #[error("{0}")]
96    InterfaceError(String),
97
98    #[error("{0}")]
99    SerializeError(String),
100
101    #[error("{0}")]
102    VisitorError(String),
103}
104
105macro_rules! from_to_string {
106    ($from:ty, $variant:ident) => {
107        impl From<$from> for Error {
108            fn from(e: $from) -> Self {
109                Error::$variant(e.to_string())
110            }
111        }
112    };
113}
114
115from_to_string!(db::DbError, DbError);
116from_to_string!(interface::InterfaceError, InterfaceError);
117from_to_string!(serialize::SerializeError, SerializeError);
118from_to_string!(visitor::VisitorError, VisitorError);