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///
25/// CONSTANTS
26///
27
28/// Maximum number of indexed fields allowed on an entity.
29///
30/// This limit keeps hashed index keys within bounded, storable sizes and
31/// simplifies sizing tests in the stores.
32pub const MAX_INDEX_FIELDS: usize = 4;
33
34///
35/// ICYDB ACTOR PRELUDE
36/// using _ brings traits into scope and avoids name conflicts
37///
38
39pub mod prelude {
40    pub use crate::{
41        db,
42        db::{
43            executor::SaveExecutor,
44            primitives::{
45                self, FilterDsl, FilterExpr, FilterExt as _, LimitExpr, LimitExt as _, SortExpr,
46                SortExt as _,
47            },
48            query,
49            response::Response,
50        },
51        key::Key,
52        traits::{
53            CreateView as _, EntityKind as _, FilterView as _, Inner as _, Path as _,
54            UpdateView as _, View as _,
55        },
56        types::{Decimal, Ulid},
57        value::Value,
58        view::{Create, Filter, Update, View},
59    };
60    pub use candid::CandidType;
61    pub use serde::{Deserialize, Serialize};
62}
63
64///
65/// Third party re-exports
66///
67
68pub mod export {
69    pub use canic;
70    pub use ctor;
71    pub use derive_more;
72    pub use num_traits;
73    pub use remain;
74}
75
76use candid::CandidType;
77use serde::{Deserialize, Serialize};
78use thiserror::Error as ThisError;
79
80///
81/// Error
82///
83/// top level error should handle all sub-errors, but not expose the candid types
84/// as that would be a lot of them
85///
86
87#[derive(CandidType, Debug, Deserialize, Serialize, ThisError)]
88pub enum Error {
89    // third party
90    #[error("{0}")]
91    CanicError(String),
92
93    #[error("{0}")]
94    DbError(String),
95
96    #[error("{0}")]
97    InterfaceError(String),
98
99    #[error("{0}")]
100    SerializeError(String),
101
102    #[error("{0}")]
103    VisitorError(String),
104}
105
106macro_rules! from_to_string {
107    ($from:ty, $variant:ident) => {
108        impl From<$from> for Error {
109            fn from(e: $from) -> Self {
110                Error::$variant(e.to_string())
111            }
112        }
113    };
114}
115
116from_to_string!(canic::Error, CanicError);
117from_to_string!(db::DbError, DbError);
118from_to_string!(interface::InterfaceError, InterfaceError);
119from_to_string!(serialize::SerializeError, SerializeError);
120from_to_string!(visitor::VisitorError, VisitorError);