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 json;
20pub mod page;
21pub mod projection;
22pub mod rpc;
23pub mod schema;
24pub mod transport;
25pub mod validators;
26pub mod value;
27
28// -----------------------------------------------------------------------------
29// Decimal scalar
30//
31// Selected at compile time via mutually-exclusive Cargo features. Generated
32// code references `cratestack::Decimal` regardless of backend, so swapping
33// backends is a workspace-feature flip rather than a code change.
34// -----------------------------------------------------------------------------
35
36#[cfg(all(feature = "decimal-rust-decimal", feature = "decimal-bigdecimal"))]
37compile_error!(
38    "cratestack: features `decimal-rust-decimal` and `decimal-bigdecimal` are mutually exclusive"
39);
40
41#[cfg(not(any(feature = "decimal-rust-decimal", feature = "decimal-bigdecimal")))]
42compile_error!(
43    "cratestack: enable exactly one Decimal backend feature (`decimal-rust-decimal` or `decimal-bigdecimal`)"
44);
45
46#[cfg(feature = "decimal-rust-decimal")]
47pub type Decimal = rust_decimal::Decimal;
48
49#[cfg(feature = "decimal-bigdecimal")]
50compile_error!(
51    "cratestack: the `decimal-bigdecimal` backend is reserved but not yet implemented; use `decimal-rust-decimal` for now"
52);
53
54/// Body bytes carried through the transport layer.
55pub type CoolBody = bytes::Bytes;
56
57// Backwards-compatible re-exports so external crates keep using
58// `cratestack_core::Type` rather than `cratestack_core::module::Type`.
59
60pub use audit::{
61    AuditActor, AuditEvent, AuditOperation, AuditSink, MulticastAuditSink, NoopAuditSink,
62    TransactionIsolation,
63};
64pub use batch::{
65    BATCH_MAX_ITEMS, BatchItemError, BatchItemResult, BatchItemStatus, BatchRequest, BatchResponse,
66    BatchSummary, find_duplicate_position,
67};
68pub use codec::{CoolCodec, CoolEnvelope, NoEnvelope};
69pub use context::{
70    AuthProvider, CoolAuthIdentity, CoolContext, PrincipalContext, PrincipalFacet, RequestContext,
71};
72pub use envelope::{
73    HmacEnvelope, InMemoryNonceStore, KeyProvider, NonceStore, SealedEnvelope, StaticKeyProvider,
74};
75pub use error::{CoolError, CoolErrorResponse, parse_cuid};
76pub use events::{
77    CoolEventBus, CoolEventEnvelope, CoolEventFuture, ModelEvent, ModelEventKind, event_topic,
78    parse_emit_attribute,
79};
80pub use json::Json;
81pub use page::{Page, PageInfo};
82pub use projection::ProjectionDecoder;
83pub use schema::{
84    Attribute, AuthBlock, ConfigBlock, ConfigEntry, Datasource, EnumDecl, EnumVariant, Field,
85    MixinDecl, Model, OwnedSchemaSummary, Procedure, ProcedureArg, ProcedureKind, Schema,
86    SchemaSummary, SelectionQuery, SourceSpan, TransportStyle, TypeArity, TypeDecl, TypeRef, View,
87    ViewSource,
88};
89pub use transport::{
90    OpDescriptor, OpKind, RouteTransportCapabilities, RouteTransportDescriptor,
91    canonical_request_string,
92};
93pub use validators::{
94    validate_email, validate_iso4217, validate_length, validate_range_decimal, validate_range_i64,
95    validate_uri,
96};
97pub use value::Value;