From 73bbeda18b9dc9935a4d78b5b3143ca2f82fedbd Mon Sep 17 00:00:00 2001 From: William Boxhall Date: Tue, 19 May 2020 16:40:41 +1000 Subject: [PATCH] Formatting --- .../cultureamp/eventsourcing/Configuration.kt | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/main/kotlin/com/cultureamp/eventsourcing/Configuration.kt b/src/main/kotlin/com/cultureamp/eventsourcing/Configuration.kt index 69a6766..c1b3f53 100644 --- a/src/main/kotlin/com/cultureamp/eventsourcing/Configuration.kt +++ b/src/main/kotlin/com/cultureamp/eventsourcing/Configuration.kt @@ -5,16 +5,16 @@ import java.util.* import kotlin.reflect.KClass data class Configuration( - val creationCommandClass: KClass, - val updateCommandClass: KClass, - val create: (CC) -> Either, - val update: A.(UC) -> Either>, - val created: (CE) -> A, - val updated: A.(UE) -> A, - val aggregateType: A.() -> String + val creationCommandClass: KClass, + val updateCommandClass: KClass, + val create: (CC) -> Either, + val update: A.(UC) -> Either>, + val created: (CE) -> A, + val updated: A.(UE) -> A, + val aggregateType: A.() -> String ) { object Builder { - inline fun create(noinline create: (CC) -> Either): CreateBuilder { + inline fun create(noinline create: (CC) -> Either): CreateBuilder { return CreateBuilder(CC::class, create) } } @@ -22,26 +22,26 @@ data class Configuration from( - noinline create: (CC) -> Either, - noinline update: A.(UC) -> Either>, - noinline created: (CE) -> A, - noinline updated: A.(UE) -> A = { _ -> this }, - noinline aggregateType: A.() -> String = { this::class.simpleName!! } + noinline create: (CC) -> Either, + noinline update: A.(UC) -> Either>, + noinline created: (CE) -> A, + noinline updated: A.(UE) -> A = { _ -> this }, + noinline aggregateType: A.() -> String = { this::class.simpleName!! } ): Configuration { return Configuration(CC::class, UC::class, create, update, created, updated, aggregateType) } inline fun fromStateless( - noinline create: (CC) -> Either, - noinline update: (UC) -> Either>, - instance: A, - noinline aggregateType: A.() -> String = { this::class.simpleName!! } + noinline create: (CC) -> Either, + noinline update: (UC) -> Either>, + instance: A, + noinline aggregateType: A.() -> String = { this::class.simpleName!! } ): Configuration { return from(create, { update(it) }, { instance }, { instance }, aggregateType) } inline fun > fromTypedAggregate( - aggregateConstructor: AggregateConstructor + aggregateConstructor: AggregateConstructor ): Configuration { val created = aggregateConstructor::created val create = aggregateConstructor::create @@ -52,8 +52,8 @@ data class Configuration> fromTypedAggregate( - aggregateConstructor: AggregateConstructorWithProjection, - projection: P + aggregateConstructor: AggregateConstructorWithProjection, + projection: P ): Configuration> { return fromTypedAggregate>(aggregateConstructor.partial(projection)) } @@ -62,12 +62,12 @@ data class Configuration = create(creationCommand).map { domainEvent -> val aggregate = created(domainEvent) val event = Event( - id = UUID.randomUUID(), - aggregateId = creationCommand.aggregateId, - aggregateSequence = 1, - createdAt = DateTime(), - metadata = metadata, - domainEvent = domainEvent) + id = UUID.randomUUID(), + aggregateId = creationCommand.aggregateId, + aggregateSequence = 1, + createdAt = DateTime(), + metadata = metadata, + domainEvent = domainEvent) eventStore.sink(listOf(event), creationCommand.aggregateId, aggregate.aggregateType()) }.flatten() @@ -82,12 +82,12 @@ data class Configuration Event( - id = UUID.randomUUID(), - aggregateId = updateCommand.aggregateId, - aggregateSequence = offset + index, - createdAt = createdAt, - metadata = metadata, - domainEvent = domainEvent + id = UUID.randomUUID(), + aggregateId = updateCommand.aggregateId, + aggregateSequence = offset + index, + createdAt = createdAt, + metadata = metadata, + domainEvent = domainEvent ) } eventStore.sink(storableEvents, updateCommand.aggregateId, updated.aggregateType()) @@ -97,44 +97,44 @@ data class Configuration): A = updated(created(creationEvent), updateEvents) private fun updated(initial: A, updateEvents: List): A = - updateEvents.fold(initial) { aggregate, updateEvent -> updated(aggregate, updateEvent) } + updateEvents.fold(initial) { aggregate, updateEvent -> updated(aggregate, updateEvent) } } class CreateBuilder( - val _creationCommandClass: KClass, - val _create: (CC) -> Either + val _creationCommandClass: KClass, + val _create: (CC) -> Either ) { inline fun update(noinline update: A.(UC) -> Either>) = UpdateBuilder(_creationCommandClass, UC::class, _create, update) } class UpdateBuilder( - private val creationCommandClass: KClass, - private val updateCommandClass: KClass, - private val create: (CC) -> Either, - private val update: A.(UC) -> Either> + private val creationCommandClass: KClass, + private val updateCommandClass: KClass, + private val create: (CC) -> Either, + private val update: A.(UC) -> Either> ) { fun created(created: (CE) -> A) = CreatedBuilder(creationCommandClass, updateCommandClass, create, update, created) fun buildStateless(instance: A, aggregateType: A.() -> String = { this::class.simpleName!! }) = UpdatedBuilder(creationCommandClass, updateCommandClass, create, update, { instance }, { instance }).build(aggregateType) } class CreatedBuilder( - private val creationCommandClass: KClass, - private val updateCommandClass: KClass, - private val create: (CC) -> Either, - private val update: A.(UC) -> Either>, - private val created: (CE) -> A) { + private val creationCommandClass: KClass, + private val updateCommandClass: KClass, + private val create: (CC) -> Either, + private val update: A.(UC) -> Either>, + private val created: (CE) -> A) { fun updated(updated: A.(UE) -> A) = UpdatedBuilder(creationCommandClass, updateCommandClass, create, update, created, updated) fun build() = UpdatedBuilder(creationCommandClass, updateCommandClass, create, update, created, { _ -> this }).build() } class UpdatedBuilder( - private val creationCommandClass: KClass, - private val updateCommandClass: KClass, - private val create: (CC) -> Either, - private val update: A.(UC) -> Either>, - private val created: (CE) -> A, - private val updated: A.(UE) -> A + private val creationCommandClass: KClass, + private val updateCommandClass: KClass, + private val create: (CC) -> Either, + private val update: A.(UC) -> Either>, + private val created: (CE) -> A, + private val updated: A.(UE) -> A ) { fun build(aggregateType: A.() -> String = { this::class.simpleName!! }) = Configuration(creationCommandClass, updateCommandClass, create, update, created, updated, aggregateType)