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::{
85 EnumVariantModel, FieldInsertGeneration, FieldKind, FieldModel, FieldStorageDecode,
86 FieldWriteManagement, RelationStrength,
87 };
88 }
89
90 pub mod index {
91 pub use icydb_core::model::{
92 IndexExpression, IndexKeyItem, IndexKeyItemsRef, IndexModel, IndexPredicateMetadata,
93 };
94 }
95
96 pub use entity::EntityModel;
97 pub use field::FieldModel;
98 pub use index::{IndexExpression, IndexModel};
99}
100
101#[doc(hidden)]
102pub mod metrics {
103 pub use icydb_core::metrics::{
104 EventCounters, EventReport, MetricsSink, metrics_report, metrics_reset_all,
105 };
106}
107
108pub mod visitor {
109 pub use icydb_core::visitor::{
110 Issue, PathSegment, SanitizeFieldDescriptor, ScopedContext, ValidateFieldDescriptor,
111 VisitableFieldDescriptor, VisitorContext, VisitorCore, VisitorError, VisitorIssues,
112 VisitorMutCore, drive_sanitize_fields, drive_validate_fields, drive_visitable_fields,
113 drive_visitable_fields_mut, perform_visit, perform_visit_mut,
114 };
115 pub use icydb_core::{
116 sanitize::{SanitizeWriteContext, SanitizeWriteMode, sanitize, sanitize_with_context},
117 validate::validate,
118 };
119}
120
121pub mod base;
123pub mod db;
124pub mod error;
125pub mod traits;
126pub use error::Error;
127
128#[doc(hidden)]
131pub mod __macro {
132 pub use crate::db::execute_generated_storage_report;
133 #[cfg(feature = "sql")]
134 pub use icydb_core::db::LoweredSqlCommand;
135 pub use icydb_core::db::{
136 DataStore, DbSession as CoreDbSession, EntityRuntimeHooks, IndexStore, StoreRegistry,
137 };
138}
139
140#[doc(hidden)]
147pub mod __reexports {
148 pub use candid;
149 pub use canic_cdk;
150 pub use canic_memory;
151 pub use ctor;
152 pub use derive_more;
153 pub use icydb_derive;
154 pub use remain;
155 pub use serde;
156}
157
158pub mod prelude {
164 pub use crate::{
165 db,
166 db::{
167 query,
168 query::{
169 FilterExpr, SortExpr,
170 builder::{
171 FieldRef, count, count_by, exists, first, last, max, max_by, min, min_by, sum,
172 },
173 predicate::Predicate,
174 },
175 },
176 traits::{
177 Collection as _, EntityKind as _, EntityValue, Inner as _, MapCollection as _,
178 Path as _,
179 },
180 types::*,
181 value::Value,
182 };
183 pub use candid::CandidType;
184 pub use serde::{Deserialize, Serialize};
185}
186
187pub mod design {
193 pub mod prelude {
194 pub use ::candid::CandidType;
195 pub use ::derive_more;
196
197 pub use crate::{
198 base, db,
199 db::query::builder::{
200 FieldRef, count, count_by, exists, first, last, max, max_by, min, min_by, sum,
201 },
202 macros::*,
203 traits::{
204 Collection as _, EntityKind, EntityValue as _, FieldValue as _, Inner as _,
205 MapCollection as _, Path as _, Sanitize as _, Sanitizer, Serialize as _,
206 Validate as _, ValidateCustom, Validator, Visitable as _,
207 },
208 types::*,
209 value::Value,
210 visitor::VisitorContext,
211 visitor::{SanitizeWriteContext, SanitizeWriteMode},
212 };
213 }
214}
215
216pub const VERSION: &str = env!("CARGO_PKG_VERSION");
225
226#[macro_export]
232macro_rules! start {
233 () => {
234 include!(concat!(env!("OUT_DIR"), "/actor.rs"));
236 };
237}
238
239#[macro_export]
241#[expect(clippy::crate_in_macro_def)]
242macro_rules! db {
243 () => {
244 crate::db()
245 };
246}
247
248pub fn sanitize(node: &mut dyn Visitable) -> Result<(), Error> {
254 icydb_core::sanitize::sanitize(node)
255 .map_err(InternalError::from)
256 .map_err(Error::from)
257}
258
259pub fn validate(node: &dyn Visitable) -> Result<(), Error> {
261 icydb_core::validate::validate(node)
262 .map_err(InternalError::from)
263 .map_err(Error::from)
264}
265
266pub fn serialize<T>(ty: &T) -> Result<Vec<u8>, Error>
271where
272 T: Serialize,
273{
274 icydb_core::serialize::serialize(ty)
275 .map_err(|err| {
276 InternalError::new(
277 ErrorClass::Internal,
278 ErrorOrigin::Serialize,
279 err.to_string(),
280 )
281 })
282 .map_err(Error::from)
283}
284
285pub fn deserialize<T>(bytes: &[u8]) -> Result<T, Error>
290where
291 T: DeserializeOwned,
292{
293 icydb_core::serialize::deserialize(bytes)
294 .map_err(|err| {
295 InternalError::new(
296 ErrorClass::Internal,
297 ErrorOrigin::Serialize,
298 err.to_string(),
299 )
300 })
301 .map_err(Error::from)
302}