1extern crate self as icydb;
60
61use icydb_core::{
62 error::{ErrorClass, ErrorOrigin, InternalError},
63 traits::Visitable,
64};
65use serde::{Serialize, de::DeserializeOwned};
66
67pub use icydb_build as build;
69pub use icydb_build::build;
70pub use icydb_schema as schema;
71pub use icydb_schema_derive as macros;
72
73#[doc(hidden)]
75pub use icydb_core::{types, value};
76
77#[doc(hidden)]
78pub mod model {
79 pub mod entity {
80 pub use icydb_core::model::EntityModel;
81 }
82
83 pub mod field {
84 pub use icydb_core::model::{FieldKind, FieldModel, RelationStrength};
85 }
86
87 pub mod index {
88 pub use icydb_core::model::IndexModel;
89 }
90
91 pub use entity::EntityModel;
92 pub use field::FieldModel;
93 pub use index::IndexModel;
94}
95
96#[doc(hidden)]
97pub mod metrics {
98 pub use icydb_core::metrics::{EventReport, MetricsSink, metrics_report, metrics_reset_all};
99}
100
101pub mod patch {
102 pub use icydb_core::patch::{ListPatch, MapPatch, MergePatchError, SetPatch};
103}
104
105pub mod visitor {
106 pub use icydb_core::visitor::{
107 Issue, PathSegment, ScopedContext, VisitorContext, VisitorCore, VisitorError,
108 VisitorIssues, VisitorMutCore, perform_visit, perform_visit_mut,
109 };
110 pub use icydb_core::{sanitize::sanitize, validate::validate};
111}
112
113pub mod base;
115pub mod db;
116pub mod error;
117pub mod traits;
118pub use error::Error;
119
120#[doc(hidden)]
123pub mod __macro {
124 pub use icydb_core::db::{
125 DataStore, DbSession as CoreDbSession, EntityRuntimeHooks, IndexStore, StoreRegistry,
126 };
127 pub use icydb_core::traits::{
128 AsView as CoreAsView, CreateView as CoreCreateView, UpdateView as CoreUpdateView,
129 };
130}
131
132#[doc(hidden)]
139pub mod __reexports {
140 pub use candid;
141 pub use canic_cdk;
142 pub use canic_memory;
143 pub use ctor;
144 pub use derive_more;
145 pub use icydb_derive;
146 pub use num_traits;
147 pub use remain;
148 pub use serde;
149}
150
151pub mod prelude {
157 pub use crate::{
158 db,
159 db::{
160 query,
161 query::{
162 FilterExpr, SortExpr,
163 builder::{
164 FieldRef, count, count_by, exists, first, last, max, max_by, min, min_by, sum,
165 },
166 predicate::Predicate,
167 },
168 },
169 traits::{
170 AsView, Collection as _, Create, CreateView as _, EntityKind as _, EntityValue,
171 Inner as _, MapCollection as _, Path as _, Update, UpdateView as _, View,
172 },
173 types::*,
174 value::Value,
175 };
176 pub use candid::CandidType;
177 pub use serde::{Deserialize, Serialize};
178}
179
180pub mod design {
186 pub mod prelude {
187 pub use ::candid::CandidType;
188 pub use ::derive_more;
189
190 pub use crate::{
191 base, db,
192 db::query::builder::{
193 FieldRef, count, count_by, exists, first, last, max, max_by, min, min_by, sum,
194 },
195 macros::*,
196 traits::{
197 AsView, Collection as _, Create, CreateView, EntityKind, EntityValue as _,
198 FieldValue as _, Inner as _, MapCollection as _, Path as _, Sanitize as _,
199 Sanitizer, Serialize as _, Update, UpdateView, Validate as _, ValidateCustom,
200 Validator, View, Visitable as _,
201 },
202 types::*,
203 value::Value,
204 visitor::VisitorContext,
205 };
206 }
207}
208
209pub const VERSION: &str = env!("CARGO_PKG_VERSION");
218
219#[macro_export]
225macro_rules! start {
226 () => {
227 include!(concat!(env!("OUT_DIR"), "/actor.rs"));
229 };
230}
231
232#[macro_export]
234#[expect(clippy::crate_in_macro_def)]
235macro_rules! db {
236 () => {
237 crate::db()
238 };
239}
240
241pub fn sanitize(node: &mut dyn Visitable) -> Result<(), Error> {
247 icydb_core::sanitize::sanitize(node)
248 .map_err(InternalError::from)
249 .map_err(Error::from)
250}
251
252pub fn validate(node: &dyn Visitable) -> Result<(), Error> {
254 icydb_core::validate::validate(node)
255 .map_err(InternalError::from)
256 .map_err(Error::from)
257}
258
259pub fn serialize<T>(ty: &T) -> Result<Vec<u8>, Error>
264where
265 T: Serialize,
266{
267 icydb_core::serialize::serialize(ty)
268 .map_err(|err| {
269 InternalError::new(
270 ErrorClass::Internal,
271 ErrorOrigin::Serialize,
272 err.to_string(),
273 )
274 })
275 .map_err(Error::from)
276}
277
278pub fn deserialize<T>(bytes: &[u8]) -> Result<T, Error>
283where
284 T: DeserializeOwned,
285{
286 icydb_core::serialize::deserialize(bytes)
287 .map_err(|err| {
288 InternalError::new(
289 ErrorClass::Internal,
290 ErrorOrigin::Serialize,
291 err.to_string(),
292 )
293 })
294 .map_err(Error::from)
295}