truncate method

Future<AggregateStateResult<TEvent, TValue, TId, TState>> truncate(
  1. TAggregate aggregate
)

Truncate AggregateState of given aggregate

Implementation

Future<AggregateStateResult<TEvent, TValue, TId, TState>> truncate(
    TAggregate aggregate) async {
  try {
    aggregate.ensureExists();
    await _events.truncateStream(
      StreamName.from(aggregate),
      aggregate.expectedVersion,
      aggregate.expectedVersion.toTruncatePosition(
        StreamTruncatePosition.Exclude,
      ),
    );
    return AggregateStateResult.ok(
      current: aggregate.current,
      previous: aggregate.original,
    );
  } on StreamNotFoundException {
    return AggregateStateResult.error(
      AggregateNotFoundException(
        TAggregate,
        aggregate.id,
      ),
      aggregate,
    );
  } on Exception catch (error) {
    return AggregateStateResult.error(
      error,
      aggregate..rollback(),
    );
  }
}