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        value::Value,
72        view::{Create, Filter, Update, View},
73    };
74    pub use candid::CandidType;
75    pub use serde::{Deserialize, Serialize};
76}
77
78use candid::CandidType;
79use serde::{Deserialize, Serialize};
80use thiserror::Error as ThisError;
81
82///
83/// Error
84///
85/// top level error should handle all sub-errors, but not expose the candid types
86/// as that would be a lot of them
87///
88
89#[derive(CandidType, Debug, Deserialize, Serialize, ThisError)]
90pub enum Error {
91    #[error("{0}")]
92    DbError(String),
93
94    #[error("{0}")]
95    InterfaceError(String),
96
97    #[error("{0}")]
98    SerializeError(String),
99
100    #[error("{0}")]
101    VisitorError(String),
102}
103
104macro_rules! from_to_string {
105    ($from:ty, $variant:ident) => {
106        impl From<$from> for Error {
107            fn from(e: $from) -> Self {
108                Error::$variant(e.to_string())
109            }
110        }
111    };
112}
113
114from_to_string!(db::DbError, DbError);
115from_to_string!(interface::InterfaceError, InterfaceError);
116from_to_string!(serialize::SerializeError, SerializeError);
117from_to_string!(visitor::VisitorError, VisitorError);