Skip to content

Cratis Chronicle projections: declare NotRewindable

In Cratis Chronicle, NotRewindable() records IsRewindable = false on a projection definition. Use it to declare that flag, not to prevent observer replay: the flag is separate from observer replayability and does not change event handling.

Call NotRewindable() on the projection builder:

using Cratis.Chronicle.Projections;
public class DecNotRewindableAuditLogProjection : IProjectionFor<DecNotRewindableAuditLogEntry>
{
public void Define(IProjectionBuilderFor<DecNotRewindableAuditLogEntry> builder) => builder
.NotRewindable()
.FromEvery(_ => _
.Set(m => m.ProcessedAt).ToEventContextProperty(c => c.Occurred))
.From<DecNotRewindableUserAction>(_ => _
.Set(m => m.OccurredAt).ToEventContextProperty(c => c.Occurred));
}

View C# snippet source on GitHub

The client registers this definition with the Kernel with IsRewindable set to false. The From and FromEvery mappings still determine which values the projection writes.

The example targets an audit-entry read model with fields for the action and its timestamps:

public record DecNotRewindableAuditLogEntry(
string UserId,
string Action,
string Details,
DateTimeOffset OccurredAt,
DateTimeOffset ProcessedAt,
long SequenceNumber);

View C# snippet source on GitHub

These events supply the action and system information used in the examples:

using Cratis.Chronicle.Events;
[EventType]
public record DecNotRewindableUserAction(
string UserId,
string ActionType,
string Details);
[EventType]
public record DecNotRewindableSystemEvent(
string ComponentName,
string EventType,
string Data);

View C# snippet source on GitHub

The builder starts with IsRewindable set to true; NotRewindable() changes it to false. The Kernel carries that value on the engine’s projection. Observer replayability is classified separately, so do not use this flag as a substitute for replay policy.

The same declaration works with audit entries, performance metrics, and financial transactions. Each example keeps its own event mappings and read-model shape:

using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;
[EventType]
public record DecNotRewindableUserLoginAttempt(string UserId, bool Succeeded);
[EventType]
public record DecNotRewindablePermissionChange(string UserId, string Permission);
public record DecNotRewindableSecurityAuditEntry(
DateTimeOffset AuditedAt,
long SequenceNumber);
public class DecNotRewindableSecurityAuditProjection : IProjectionFor<DecNotRewindableSecurityAuditEntry>
{
public void Define(IProjectionBuilderFor<DecNotRewindableSecurityAuditEntry> builder) => builder
.NotRewindable()
.FromEvery(_ => _
.Set(m => m.AuditedAt).ToEventContextProperty(c => c.Occurred)
.Set(m => m.SequenceNumber).ToEventContextProperty(c => c.SequenceNumber))
.From<DecNotRewindableUserLoginAttempt>()
.From<DecNotRewindablePermissionChange>();
}

View C# snippet source on GitHub

[EventType]
public record DecNotRewindableApiRequestCompleted(string Endpoint, int StatusCode, long DurationMilliseconds);
public record DecNotRewindablePerformanceMetric(DateTimeOffset Timestamp);
public class DecNotRewindablePerformanceMetricProjection : IProjectionFor<DecNotRewindablePerformanceMetric>
{
public void Define(IProjectionBuilderFor<DecNotRewindablePerformanceMetric> builder) => builder
.NotRewindable()
.From<DecNotRewindableApiRequestCompleted>(_ => _
.Set(m => m.Timestamp).ToEventContextProperty(c => c.Occurred));
}

View C# snippet source on GitHub

[EventType]
public record DecNotRewindablePaymentProcessed(string PaymentId, decimal Amount);
public record DecNotRewindableLedgerEntry(
DateTimeOffset RecordedAt,
string TransactionType);
public class DecNotRewindableTransactionLedgerProjection : IProjectionFor<DecNotRewindableLedgerEntry>
{
public void Define(IProjectionBuilderFor<DecNotRewindableLedgerEntry> builder) => builder
.NotRewindable()
.FromEvery(_ => _
.Set(m => m.RecordedAt).ToEventContextProperty(c => c.Occurred))
.From<DecNotRewindablePaymentProcessed>(_ => _
.Set(m => m.TransactionType).ToValue("PAYMENT"));
}

View C# snippet source on GitHub

You can declare the flag alongside an event sequence, passive mode, and property mappings:

using Cratis.Chronicle.Projections;
[EventType]
public record DecNotRewindableOrderReceived(string OrderId);
[EventType]
public record DecNotRewindableOrderProcessing(string OrderId);
[EventType]
public record DecNotRewindableOrderCompleted(string OrderId);
public record DecNotRewindableOrderStatus(
string Status,
DateTimeOffset LastUpdatedAt);
public class DecNotRewindableRealTimeOrderStatusProjection : IProjectionFor<DecNotRewindableOrderStatus>
{
public void Define(IProjectionBuilderFor<DecNotRewindableOrderStatus> builder) => builder
.NotRewindable()
.FromEventSequence("order-processing")
.Passive()
.FromEvery(_ => _
.Set(m => m.LastUpdatedAt).ToEventContextProperty(c => c.Occurred))
.From<DecNotRewindableOrderReceived>(_ => _
.Set(m => m.Status).ToValue("RECEIVED"))
.From<DecNotRewindableOrderProcessing>(_ => _
.Set(m => m.Status).ToValue("PROCESSING"))
.From<DecNotRewindableOrderCompleted>(_ => _
.Set(m => m.Status).ToValue("COMPLETED"));
}

View C# snippet source on GitHub

Here, FromEventSequence selects the events, Passive() selects on-demand computation, and the mappings set status and timestamps. Those choices are independent of NotRewindable(). Continue with passive projections if you want to compute a read model at read time rather than maintain stored state.