pub struct Projection { /* private fields */ }Expand description
Domain Entity: Projection
Represents a projection that aggregates events into a queryable view. Projections are materialized views derived from the event stream.
Domain Rules:
- Name must be unique within a tenant
- Name cannot be empty
- Version starts at 1 and increments
- Cannot change projection type after creation
- Status transitions must follow lifecycle rules
- Stats are accurate and updated on each event
Implementations§
Source§impl Projection
impl Projection
Sourcepub fn new(
tenant_id: TenantId,
name: String,
version: u32,
projection_type: ProjectionType,
) -> Result<Self>
pub fn new( tenant_id: TenantId, name: String, version: u32, projection_type: ProjectionType, ) -> Result<Self>
Create a new projection with validation
Sourcepub fn new_v1(
tenant_id: TenantId,
name: String,
projection_type: ProjectionType,
) -> Result<Self>
pub fn new_v1( tenant_id: TenantId, name: String, projection_type: ProjectionType, ) -> Result<Self>
Create first version of a projection
Sourcepub fn reconstruct(
id: Uuid,
tenant_id: TenantId,
name: String,
version: u32,
projection_type: ProjectionType,
status: ProjectionStatus,
config: ProjectionConfig,
stats: ProjectionStats,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
started_at: Option<DateTime<Utc>>,
stopped_at: Option<DateTime<Utc>>,
description: Option<String>,
event_types: Vec<EventType>,
metadata: Value,
) -> Self
pub fn reconstruct( id: Uuid, tenant_id: TenantId, name: String, version: u32, projection_type: ProjectionType, status: ProjectionStatus, config: ProjectionConfig, stats: ProjectionStats, created_at: DateTime<Utc>, updated_at: DateTime<Utc>, started_at: Option<DateTime<Utc>>, stopped_at: Option<DateTime<Utc>>, description: Option<String>, event_types: Vec<EventType>, metadata: Value, ) -> Self
Reconstruct projection from storage (bypasses validation)
pub fn id(&self) -> Uuid
pub fn tenant_id(&self) -> &TenantId
pub fn name(&self) -> &str
pub fn version(&self) -> u32
pub fn projection_type(&self) -> ProjectionType
pub fn status(&self) -> ProjectionStatus
pub fn config(&self) -> &ProjectionConfig
pub fn stats(&self) -> &ProjectionStats
pub fn created_at(&self) -> DateTime<Utc>
pub fn updated_at(&self) -> DateTime<Utc>
pub fn description(&self) -> Option<&str>
pub fn event_types(&self) -> &[EventType]
pub fn metadata(&self) -> &Value
Sourcepub fn mark_failed(&mut self)
pub fn mark_failed(&mut self)
Mark projection as failed
Sourcepub fn start_rebuild(&mut self) -> Result<()>
pub fn start_rebuild(&mut self) -> Result<()>
Start rebuilding the projection
Sourcepub fn update_config(&mut self, config: ProjectionConfig)
pub fn update_config(&mut self, config: ProjectionConfig)
Update configuration
Sourcepub fn set_description(&mut self, description: String) -> Result<()>
pub fn set_description(&mut self, description: String) -> Result<()>
Set description
Sourcepub fn add_event_type(&mut self, event_type: EventType) -> Result<()>
pub fn add_event_type(&mut self, event_type: EventType) -> Result<()>
Add event type filter
Sourcepub fn remove_event_type(&mut self, event_type: &EventType) -> Result<()>
pub fn remove_event_type(&mut self, event_type: &EventType) -> Result<()>
Remove event type filter
Sourcepub fn processes_event_type(&self, event_type: &EventType) -> bool
pub fn processes_event_type(&self, event_type: &EventType) -> bool
Check if projection processes this event type
Sourcepub fn update_metadata(&mut self, metadata: Value)
pub fn update_metadata(&mut self, metadata: Value)
Update metadata
Sourcepub fn stats_mut(&mut self) -> &mut ProjectionStats
pub fn stats_mut(&mut self) -> &mut ProjectionStats
Get mutable access to stats (for recording events)
Sourcepub fn is_first_version(&self) -> bool
pub fn is_first_version(&self) -> bool
Check if projection is first version
Sourcepub fn belongs_to_tenant(&self, tenant_id: &TenantId) -> bool
pub fn belongs_to_tenant(&self, tenant_id: &TenantId) -> bool
Check if projection belongs to tenant
Sourcepub fn create_next_version(&self) -> Result<Projection>
pub fn create_next_version(&self) -> Result<Projection>
Create next version
Trait Implementations§
Source§impl Clone for Projection
impl Clone for Projection
Source§fn clone(&self) -> Projection
fn clone(&self) -> Projection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Projection
impl Debug for Projection
Source§impl<'de> Deserialize<'de> for Projection
impl<'de> Deserialize<'de> for Projection
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<&Projection> for ProjectionDto
impl From<&Projection> for ProjectionDto
Source§fn from(projection: &Projection) -> Self
fn from(projection: &Projection) -> Self
Converts to this type from the input type.
Source§impl From<Projection> for ProjectionDto
impl From<Projection> for ProjectionDto
Source§fn from(projection: Projection) -> Self
fn from(projection: Projection) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for Projection
impl RefUnwindSafe for Projection
impl Send for Projection
impl Sync for Projection
impl Unpin for Projection
impl UnwindSafe for Projection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more