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