#![allow(clippy::module_inception)]
#![doc = include_str!("../README.md")]
#![cfg_attr(
not(any(feature = "graphql", feature = "sqlite", feature = "postgres", test)),
allow(dead_code)
)]
extern crate self as distributed;
#[doc(hidden)]
pub mod __private {
pub use serde;
}
pub mod aggregate;
pub mod application;
pub mod command_dispatch;
pub mod bus;
pub mod domain_event;
pub mod entity;
pub mod repository;
pub(crate) mod command_ledger;
mod commit_builder;
#[cfg(feature = "emitter")]
pub mod emitter;
pub mod graphql;
mod in_memory_repo;
pub mod lock;
#[cfg(feature = "metrics")]
pub mod metrics;
pub mod microsvc;
pub mod mutation;
pub mod outbox;
pub mod outbox_worker;
#[cfg(feature = "postgres")]
pub mod postgres_repo;
pub mod projection;
pub mod projection_protocol;
pub mod queued_repo;
pub mod read_model;
pub mod snapshot;
#[cfg(feature = "sqlite")]
pub mod sqlite_repo;
#[cfg(any(feature = "postgres", feature = "sqlite"))]
mod sqlx_repo;
pub mod table;
mod telemetry;
pub mod trace_context;
pub use entity::{
upcast_events, upcast_events_for_replay, upcast_payload, BitcodePayloadCodec, Entity,
EventRecord, EventRecordError, EventUpcaster, PayloadCodec, UpcastError, BITCODE_PAYLOAD_CODEC,
BITCODE_PAYLOAD_CODEC_VERSION,
};
pub use application::{
Application, ApplicationError, ApplicationManifest, CommandMount, CommandMountHandler,
CommandMountRegistrar, CommandSpec, ContractCompiler, DeploymentPlan, LogicalId, Module,
ModuleManifest, MountSelector, ProcessIntent, ProcessPreset, ProjectionSpec, SurfaceSpec,
APPLICATION_MANIFEST_SCHEMA_VERSION, DEPLOYMENT_PLAN_SCHEMA_VERSION,
};
pub use command_dispatch::{
CommandDispatchEnvelope, CommandDispatchError, CommandDispatchReceipt, CommandDispatcher,
LocalCommandDispatcher, RemoteCommandDispatcher, RemoteDispatchConfig, RemoteTrustMode,
SharedCommandDispatcher, APPROVED_REMOTE_DISPATCH_PROFILE, COMMAND_DISPATCH_ENVELOPE_VERSION,
};
pub use domain_event::{
DomainDeletion, DomainDeletionError, DomainEvent, DomainEventBodyDescriptor,
DomainEventBodyKind, DomainEventCaptureError, DomainEventCaptureOutcome,
DomainEventCapturePoison, DomainEventCommitGuardError, DomainEventDescriptor,
DomainEventEnvelope, DomainEventOccurrence, DomainState, DomainStateDescriptor,
DOMAIN_EVENT_BODY_CODEC, DOMAIN_EVENT_BODY_CODEC_VERSION, DOMAIN_EVENT_OCCURRENCE_VERSION,
MAX_DOMAIN_EVENT_BODY_BYTES, MAX_DOMAIN_EVENT_OCCURRENCE_WIRE_BYTES,
};
pub use projection::{LocalProjectionMounts, LocalProjectionMountsBuilder,
ProjectionArm, ProjectionAssignment, ProjectionEnvelopeField, ProjectionEventSelector,
ProjectionEventSet, ProjectionExpression, ProjectionField, ProjectionInvalidation,
ProjectionKeyField, ProjectionMutationKind, ProjectionMutationProvenance,
ProjectionObjectValueField, ProjectionOccurrenceProvenance, ProjectionOperation,
ProjectionPartition, ProjectionPlanTemplate, ProjectionProgram, ProjectionProgramError,
ProjectionProgramId, ProjectionProgramLimits, ProjectionRelationship,
ProjectionRelationshipEffect, ProjectionRelationshipEffectKind, ProjectionScalarTransform,
ProjectionTarget, ProjectionValue, ProjectionValueRef, ProjectionValueType,
ResolvedProjectionKey, ResolvedProjectionMutation, ResolvedProjectionMutationScope,
ResolvedProjectionPartition, ResolvedProjectionPartitionRef, ResolvedProjectionPlan,
ResolvedProjectionRelationshipEffect, ResolvedProjectionValue, MAX_PROJECTION_EXPRESSION_DEPTH,
MAX_PROJECTION_OPERATIONS_PER_OCCURRENCE, MAX_PROJECTION_PATH_SEGMENTS,
};
pub use mutation::{
bind_delete_to_envelope_id, bind_event_apply_mutation, bind_event_to_mutation,
bind_state_body_to_mutation, bind_state_events_to_mutation, body_bindings_for_model,
body_field_binding, compile_projection, compose_event_preview, delete_by_pk_program_for_model,
descriptor_from_factories, envelope_binding, inventory_single_model, lower_mutation_cache,
lower_single_model, portable_binding, resolve_mutation_program, state_upsert_program_for_model,
Mutation, MutationAssignment, MutationCacheEffect, MutationCacheProgram,
MutationCacheVisibility, MutationConflictTarget, MutationEventBinding, MutationExpression,
MutationField, MutationFieldCapability, MutationHandlerCatalog, MutationHandlerPlacement,
MutationHandlerRegistration, MutationInputBinding, MutationKeyCapability, MutationKeyField,
MutationKind, MutationOperation, MutationProgram, MutationProgramError, MutationProgramId,
MutationProgramLimits, MutationReturning, MutationServerInterpreter, ProjectionHandler,
ProjectionInputSource, ReadModelMutationCapabilities, ResolvedMutationValue,
MAX_MUTATION_OPERATIONS, MUTATION_OPERATION_SEMANTICS_VERSION, MUTATION_PROGRAM_IR_VERSION,
};
#[macro_export]
macro_rules! projection {
(
$vis:vis const $id:ident : $desc_ty:ty = {
name: $name:literal,
version: $version:expr,
epoch: $epoch:literal,
model: $model:ty,
$(
on {
events: [ $($event_ty:ty),+ $(,)? ],
mutation: $mutation:path,
input: { $input_key:ident : $input_src:ident },
$(,)?
}
),+ $(,)?
} $(;)?
) => {
$vis const $id: $desc_ty = {
fn __handlers() -> ::core::result::Result<
$crate::ProjectionProgram,
$crate::ProjectionProgramError,
> {
use $crate::domain_event::DomainEventContract;
let mut handlers = ::std::vec::Vec::new();
$(
{
let mutation = $mutation().program().clone();
let input_source = $crate::__projection_input_source!($input_src);
$(
handlers.push(
$crate::bind_event_apply_mutation::<$model>(
&<$event_ty>::descriptor(),
mutation.clone(),
::core::stringify!($input_key),
input_source,
)
.map_err(|e| $crate::ProjectionProgramError::InvalidOperation {
operation: ::std::string::String::from($name),
reason: e.to_string(),
})?,
);
)+
}
)+
$crate::compile_projection(
$name,
$version,
$crate::ProjectionPartition::Unit,
handlers,
)
}
fn __resolve(
occurrence: &$crate::DomainEventOccurrence,
) -> ::core::result::Result<
$crate::ResolvedProjectionPlan,
$crate::ProjectionProgramError,
> {
$crate::resolve_mutation_program(&__handlers()?, occurrence)
}
fn __lower(
plan: &$crate::ResolvedProjectionPlan,
) -> ::core::result::Result<
$crate::projection::lower::LoweredProjectionPlan,
$crate::projection::lower::ProjectionLoweringError,
> {
$crate::lower_single_model::<$model>(plan)
}
fn __inventory() -> ::core::result::Result<
$crate::projection::lower::ProjectionOutputInventory,
$crate::projection::lower::ProjectionLoweringError,
> {
$crate::inventory_single_model::<$model>()
}
$crate::descriptor_from_factories(
$name,
$version,
$epoch,
__handlers,
__resolve,
__lower,
__inventory,
)
};
};
(
$vis:vis const $id:ident : $desc_ty:ty = {
name: $name:literal,
version: $version:expr,
epoch: $epoch:literal,
model: $model:ty,
program: $program:path $(,)?
} $(;)?
) => {
$vis const $id: $desc_ty = {
fn __program() -> ::core::result::Result<
$crate::ProjectionProgram,
$crate::ProjectionProgramError,
> {
$program()
}
fn __resolve(
occurrence: &$crate::DomainEventOccurrence,
) -> ::core::result::Result<
$crate::ResolvedProjectionPlan,
$crate::ProjectionProgramError,
> {
$crate::resolve_mutation_program(&__program()?, occurrence)
}
fn __lower(
plan: &$crate::ResolvedProjectionPlan,
) -> ::core::result::Result<
$crate::projection::lower::LoweredProjectionPlan,
$crate::projection::lower::ProjectionLoweringError,
> {
$crate::lower_single_model::<$model>(plan)
}
fn __inventory() -> ::core::result::Result<
$crate::projection::lower::ProjectionOutputInventory,
$crate::projection::lower::ProjectionLoweringError,
> {
$crate::inventory_single_model::<$model>()
}
$crate::descriptor_from_factories(
$name,
$version,
$epoch,
__program,
__resolve,
__lower,
__inventory,
)
};
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __projection_input_source {
(body) => {
$crate::ProjectionInputSource::Body
};
(aggregate_id) => {
$crate::ProjectionInputSource::AggregateId
};
}
pub type SourcedResult<T = ()> = std::result::Result<T, EventRecordError>;
pub use repository::{
CommitBatch, GetStream, InboxOutcome, InboxReceipt, InboxStore, PreparedEventAppend,
ReadModelWritePlanStore, RelationalReadModelQueryStore, Repository, RepositoryError,
SnapshotStore, SnapshotWrite, StreamIdentity, StreamWrite, TransactionalCommit,
};
pub use aggregate::{hydrate, Aggregate, AggregateBuilder, AggregateRepository};
pub use in_memory_repo::{InMemoryOutboxStore, InMemoryRepository};
#[cfg(feature = "postgres")]
pub use postgres_repo::{PostgresOutboxStore, PostgresRepository};
#[cfg(feature = "sqlite")]
pub use sqlite_repo::{SqliteOutboxStore, SqliteRepository};
pub use lock::{
InMemoryLock, InMemoryLockFuture, InMemoryLockManager, Lock, LockError, LockManager,
};
#[cfg(feature = "postgres")]
pub use lock::{PostgresLock, PostgresLockManager};
#[cfg(feature = "sqlite")]
pub use lock::{SqliteLock, SqliteLockManager};
pub use outbox::{
outbox_message_key, outbox_message_schema, AggregateCommit, CommitReceipt, OutboxMessage,
OutboxMessageStatus, OutboxPublishHook, OutboxPublisherConfig, OUTBOX_MESSAGES_TABLE,
};
pub use outbox_worker::{
BusOutboxPublishHook, BusPublisher, ClaimOutboxMessages, OutboxClaimRef, OutboxDispatchOutcome,
OutboxDispatcher, OutboxPublishFailureAction, OutboxSource, OutboxStore, ReceivedOutboxMessage,
};
pub use queued_repo::{
GetAllWithOpts,
GetWithOpts,
Queueable,
QueuedRepository,
ReadOpts,
UnlockableRepository,
};
pub use read_model::{
InMemoryReadModelStore, ReadModel, ReadModelChange, ReadModelWorkspaceExt, RelationalReadModel,
RelationalReadModelIncludes, Versioned,
};
pub use table::{
ColumnType, DeleteTableRowMutation, ExpectedVersion, ForeignKey, PatchMode,
PatchTableRowMutation, PrimaryKey, RelationshipDef, RelationshipKind, RowKey, RowPatch,
RowValue, RowValues, RowWriteMode, TableAdapterCapabilities, TableColumn, TableCommitOutcome,
TableIndex, TableKind, TableMigrationArtifact, TableModel, TableMutation, TableRowMutation,
TableSchema, TableSchemaAdapter, TableSchemaAdapterCapabilities, TableSchemaBootstrap,
TableSchemaIssue, TableSchemaIssueKind, TableSchemaRegistry, TableSchemaRegistryExt,
ReadModelCatalog, TableSchemaVerification, TableStoreError, TableWritePlan,
DEFAULT_TABLE_VERSION_COLUMN,
};
pub use trace_context::{
is_valid_traceparent, TraceContext, CAUSATION_ID, CORRELATION_ID, TRACEPARENT, TRACESTATE,
};
pub use commit_builder::{
CommitBuilder, CommitBuilderExt, ReadModelWritePlanCommitExt, StagedCommitBuilder,
};
pub use snapshot::{hydrate_from_snapshot, InMemorySnapshotStore, SnapshotRecord, Snapshottable};
#[cfg(feature = "emitter")]
pub use event_emitter_rs::EventEmitter;
#[macro_export]
macro_rules! graphql_models {
($builder:expr, $($m:ident),+ $(,)?) => {
$builder $( .model::<$m::Model>($m::permissions()) )+
};
}
pub use microsvc::{
MessageEndpointDescriptor, MetricsEndpointDescriptor, ROLE_KEY, ServiceDescriptor,
ServiceObservabilityDescriptor, TraceExportMode, TracePropagationMode, TracingDescriptor,
TransportDescriptor, USER_ID_KEY,
};
pub use distributed_macros::{
aggregate, application, command, command_input_defaults, digest, module, mutation,
mutation_file, sourced, DomainEvent, DomainState, GraphqlInput, GraphqlOutput, ReadModel,
Snapshot,
};
#[cfg(feature = "emitter")]
pub use distributed_macros::enqueue;