Skip to main content

cratestack_core/
lib.rs

1//! `cratestack-core` — backend-agnostic primitives shared by every
2//! crate in the framework: schema IR, audit + envelope primitives,
3//! the `CoolError` / `CoolContext` / `Value` types, batch envelopes,
4//! RPC wire shapes, and field-level validators.
5//!
6//! The public surface is intentionally flat at the crate root: every
7//! type re-exports from a focused submodule below, so callers can
8//! keep writing `cratestack_core::CoolError` while the implementation
9//! lives in `cratestack_core::error`. New code can opt into the
10//! submodule paths directly.
11
12pub mod audit;
13pub mod batch;
14pub mod codec;
15pub mod context;
16pub mod envelope;
17pub mod error;
18pub mod events;
19pub mod find_many;
20pub mod json;
21pub mod page;
22pub mod projection;
23pub mod rpc;
24pub mod schema;
25pub mod transport;
26pub mod validators;
27pub mod value;
28
29// -----------------------------------------------------------------------------
30// Decimal scalar
31//
32// Selected at compile time via mutually-exclusive Cargo features. Generated
33// code references `cratestack::Decimal` regardless of backend, so swapping
34// backends is a workspace-feature flip rather than a code change.
35// -----------------------------------------------------------------------------
36
37#[cfg(all(feature = "decimal-rust-decimal", feature = "decimal-bigdecimal"))]
38compile_error!(
39    "cratestack: features `decimal-rust-decimal` and `decimal-bigdecimal` are mutually exclusive"
40);
41
42#[cfg(not(any(feature = "decimal-rust-decimal", feature = "decimal-bigdecimal")))]
43compile_error!(
44    "cratestack: enable exactly one Decimal backend feature (`decimal-rust-decimal` or `decimal-bigdecimal`)"
45);
46
47#[cfg(feature = "decimal-rust-decimal")]
48pub type Decimal = rust_decimal::Decimal;
49
50#[cfg(feature = "decimal-bigdecimal")]
51compile_error!(
52    "cratestack: the `decimal-bigdecimal` backend is reserved but not yet implemented; use `decimal-rust-decimal` for now"
53);
54
55/// Body bytes carried through the transport layer.
56pub type CoolBody = bytes::Bytes;
57
58// Backwards-compatible re-exports so external crates keep using
59// `cratestack_core::Type` rather than `cratestack_core::module::Type`.
60
61pub use audit::{
62    AuditActor, AuditEvent, AuditOperation, AuditSink, MulticastAuditSink, NoopAuditSink,
63    TransactionIsolation,
64};
65pub use batch::{
66    BATCH_MAX_ITEMS, BatchItemError, BatchItemResult, BatchItemStatus, BatchRequest, BatchResponse,
67    BatchSummary, find_duplicate_position,
68};
69pub use codec::{CoolCodec, CoolEnvelope, NoEnvelope};
70pub use context::{
71    AuthProvider, CoolAuthIdentity, CoolContext, PrincipalContext, PrincipalFacet, RequestContext,
72};
73pub use envelope::{
74    HmacEnvelope, InMemoryNonceStore, KeyProvider, NonceStore, SealedEnvelope, StaticKeyProvider,
75};
76pub use error::{CoolError, CoolErrorResponse, DbErrorInfo, parse_cuid};
77pub use events::{
78    CoolEventBus, CoolEventEnvelope, CoolEventFuture, ModelEvent, ModelEventKind, event_topic,
79    parse_emit_attribute,
80};
81pub use find_many::FieldFilterInput;
82pub use json::Json;
83pub use page::{MAX_LIST_LIMIT, Page, PageInfo, PageInput};
84pub use projection::ProjectionDecoder;
85pub use schema::{
86    Attribute, AuthBlock, ConfigBlock, ConfigEntry, Datasource, EnumDecl, EnumVariant, Field,
87    MixinDecl, Model, OwnedSchemaSummary, Procedure, ProcedureArg, ProcedureKind, Schema,
88    SchemaSummary, SelectionQuery, SourceSpan, TransportStyle, TypeArity, TypeDecl, TypeRef, View,
89    ViewSource, parse_composite_id_attribute, parse_composite_unique_attribute,
90};
91pub use transport::{
92    OpDescriptor, OpKind, RouteTransportCapabilities, RouteTransportDescriptor,
93    canonical_request_string,
94};
95pub use validators::{
96    validate_email, validate_iso4217, validate_length, validate_range_decimal, validate_range_i64,
97    validate_uri,
98};
99pub use value::Value;