diff --git a/build.gradle.kts b/build.gradle.kts index 5ce7c34..1346f72 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -54,7 +54,7 @@ allprojects { localOnly = true } - project.group = "io.connorwyatt.common" + project.group = "com.github.connorwyatt.common" project.version = scmVersion.version } diff --git a/configuration/src/main/kotlin/io/connorwyatt/common/configuration/ConfigurationUtilities.kt b/configuration/src/main/kotlin/com/github/connorwyatt/common/configuration/ConfigurationUtilities.kt similarity index 95% rename from configuration/src/main/kotlin/io/connorwyatt/common/configuration/ConfigurationUtilities.kt rename to configuration/src/main/kotlin/com/github/connorwyatt/common/configuration/ConfigurationUtilities.kt index ec7e2ae..fe9ce18 100644 --- a/configuration/src/main/kotlin/io/connorwyatt/common/configuration/ConfigurationUtilities.kt +++ b/configuration/src/main/kotlin/com/github/connorwyatt/common/configuration/ConfigurationUtilities.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.configuration +package com.github.connorwyatt.common.configuration import com.sksamuel.hoplite.ConfigLoaderBuilder import com.sksamuel.hoplite.addEnvironmentSource diff --git a/configuration/src/test/kotlin/io/connorwyatt/common/configuration/ConfigurationUtilitiesTests.kt b/configuration/src/test/kotlin/com/github/connorwyatt/common/configuration/ConfigurationUtilitiesTests.kt similarity index 95% rename from configuration/src/test/kotlin/io/connorwyatt/common/configuration/ConfigurationUtilitiesTests.kt rename to configuration/src/test/kotlin/com/github/connorwyatt/common/configuration/ConfigurationUtilitiesTests.kt index e3df634..502eed2 100644 --- a/configuration/src/test/kotlin/io/connorwyatt/common/configuration/ConfigurationUtilitiesTests.kt +++ b/configuration/src/test/kotlin/com/github/connorwyatt/common/configuration/ConfigurationUtilitiesTests.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.configuration +package com.github.connorwyatt.common.configuration import org.junit.jupiter.api.Test import strikt.api.expectThat diff --git a/data/src/main/kotlin/com/github/connorwyatt/common/data/models/Versioned.kt b/data/src/main/kotlin/com/github/connorwyatt/common/data/models/Versioned.kt new file mode 100644 index 0000000..ea829a1 --- /dev/null +++ b/data/src/main/kotlin/com/github/connorwyatt/common/data/models/Versioned.kt @@ -0,0 +1,5 @@ +package com.github.connorwyatt.common.data.models + +interface Versioned { + val version: Long +} diff --git a/data/src/main/kotlin/io/connorwyatt/common/data/models/Versioned.kt b/data/src/main/kotlin/io/connorwyatt/common/data/models/Versioned.kt deleted file mode 100644 index 3e4b156..0000000 --- a/data/src/main/kotlin/io/connorwyatt/common/data/models/Versioned.kt +++ /dev/null @@ -1,5 +0,0 @@ -package io.connorwyatt.common.data.models - -interface Versioned { - val version: Long -} diff --git a/eventstore/mongodb-models/src/main/kotlin/io/connorwyatt/common/eventstore/mongodbmodels/CursorDocument.kt b/eventstore/mongodb-models/src/main/kotlin/com/github/connorwyatt/common/eventstore/mongodbmodels/CursorDocument.kt similarity index 76% rename from eventstore/mongodb-models/src/main/kotlin/io/connorwyatt/common/eventstore/mongodbmodels/CursorDocument.kt rename to eventstore/mongodb-models/src/main/kotlin/com/github/connorwyatt/common/eventstore/mongodbmodels/CursorDocument.kt index db856c5..b020e1e 100644 --- a/eventstore/mongodb-models/src/main/kotlin/io/connorwyatt/common/eventstore/mongodbmodels/CursorDocument.kt +++ b/eventstore/mongodb-models/src/main/kotlin/com/github/connorwyatt/common/eventstore/mongodbmodels/CursorDocument.kt @@ -1,7 +1,7 @@ -package io.connorwyatt.common.eventstore.mongodbmodels +package com.github.connorwyatt.common.eventstore.mongodbmodels -import io.connorwyatt.common.eventstore.eventhandlers.EventHandler.Cursor -import io.connorwyatt.common.mongodb.CollectionName +import com.github.connorwyatt.common.eventstore.eventhandlers.EventHandler.Cursor +import com.github.connorwyatt.common.mongodb.CollectionName import org.bson.codecs.pojo.annotations.BsonId @CollectionName("cursors") diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/EventStoreClientWrapper.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/EventStoreClientWrapper.kt similarity index 61% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/EventStoreClientWrapper.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/EventStoreClientWrapper.kt index b1aa552..9fa8dbc 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/EventStoreClientWrapper.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/EventStoreClientWrapper.kt @@ -1,41 +1,48 @@ -package io.connorwyatt.common.eventstore +package com.github.connorwyatt.common.eventstore import com.eventstore.dbclient.* -import io.connorwyatt.common.eventstore.streams.StreamDescriptor +import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor import kotlinx.coroutines.future.await class EventStoreClientWrapper(private val eventStoreDBClient: EventStoreDBClient) { suspend fun readStream( streamDescriptor: StreamDescriptor, readStreamOptions: ReadStreamOptions, - ): ReadResult { + ): com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.ReadResult { val readResult = try { eventStoreDBClient .readStream(streamDescriptor.streamName, readStreamOptions) .await() } catch (exception: Exception) { - return ReadResult.Failure(exception) + return com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.ReadResult + .Failure(exception) } - return ReadResult.Success(readResult.events, readResult.lastStreamPosition) + return com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.ReadResult.Success( + readResult.events, + readResult.lastStreamPosition + ) } suspend fun appendToStream( streamDescriptor: StreamDescriptor, options: AppendToStreamOptions, events: List, - ): WriteResult { + ): com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.WriteResult { val writeResult = try { eventStoreDBClient .appendToStream(streamDescriptor.streamName, options, *events.toTypedArray()) .await() } catch (exception: Exception) { - return WriteResult.Failure(exception) + return com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.WriteResult + .Failure(exception) } - return WriteResult.Success(writeResult.logPosition.commitUnsigned) + return com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.WriteResult.Success( + writeResult.logPosition.commitUnsigned + ) } fun subscribeToStream( @@ -70,14 +77,18 @@ class EventStoreClientWrapper(private val eventStoreDBClient: EventStoreDBClient } sealed interface ReadResult { - data class Success(val events: List, val streamPosition: Long) : ReadResult + data class Success(val events: List, val streamPosition: Long) : + com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.ReadResult - data class Failure(val exception: Exception) : ReadResult + data class Failure(val exception: Exception) : + com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.ReadResult } sealed interface WriteResult { - data class Success(val streamPosition: Long) : WriteResult + data class Success(val streamPosition: Long) : + com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.WriteResult - data class Failure(val exception: Exception) : WriteResult + data class Failure(val exception: Exception) : + com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.WriteResult } } diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/aggregates/Aggregate.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/aggregates/Aggregate.kt similarity index 88% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/aggregates/Aggregate.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/aggregates/Aggregate.kt index 0f5305c..2bbf8b6 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/aggregates/Aggregate.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/aggregates/Aggregate.kt @@ -1,7 +1,7 @@ -package io.connorwyatt.common.eventstore.aggregates +package com.github.connorwyatt.common.eventstore.aggregates -import io.connorwyatt.common.eventstore.events.Event -import io.connorwyatt.common.eventstore.events.EventEnvelope +import com.github.connorwyatt.common.eventstore.events.Event +import com.github.connorwyatt.common.eventstore.events.EventEnvelope import kotlin.reflect.KClass abstract class Aggregate(val id: String) { diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/aggregates/AggregateMap.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/aggregates/AggregateMap.kt similarity index 93% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/aggregates/AggregateMap.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/aggregates/AggregateMap.kt index f65cd11..7bcdfc5 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/aggregates/AggregateMap.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/aggregates/AggregateMap.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.eventstore.aggregates +package com.github.connorwyatt.common.eventstore.aggregates import kotlin.reflect.KClass diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/aggregates/AggregateMapDefinition.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/aggregates/AggregateMapDefinition.kt similarity index 79% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/aggregates/AggregateMapDefinition.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/aggregates/AggregateMapDefinition.kt index 6463c52..b389607 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/aggregates/AggregateMapDefinition.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/aggregates/AggregateMapDefinition.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.eventstore.aggregates +package com.github.connorwyatt.common.eventstore.aggregates import kotlin.reflect.KClass diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/aggregates/AggregatesRepository.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/aggregates/AggregatesRepository.kt similarity index 85% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/aggregates/AggregatesRepository.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/aggregates/AggregatesRepository.kt index 1a79d56..3201864 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/aggregates/AggregatesRepository.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/aggregates/AggregatesRepository.kt @@ -1,7 +1,7 @@ -package io.connorwyatt.common.eventstore.aggregates +package com.github.connorwyatt.common.eventstore.aggregates -import io.connorwyatt.common.eventstore.events.EventsRepository -import io.connorwyatt.common.eventstore.streams.StreamDescriptor +import com.github.connorwyatt.common.eventstore.events.EventsRepository +import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor import kotlin.reflect.KClass class AggregatesRepository( diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/configuration/EventStoreConfiguration.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/configuration/EventStoreConfiguration.kt similarity index 64% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/configuration/EventStoreConfiguration.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/configuration/EventStoreConfiguration.kt index 3be059e..a64d841 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/configuration/EventStoreConfiguration.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/configuration/EventStoreConfiguration.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.eventstore.configuration +package com.github.connorwyatt.common.eventstore.configuration data class EventStoreConfiguration( val connectionString: String?, diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/EventHandler.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/EventHandler.kt similarity index 86% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/EventHandler.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/EventHandler.kt index 34dc31f..45fced5 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/EventHandler.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/EventHandler.kt @@ -1,8 +1,8 @@ -package io.connorwyatt.common.eventstore.eventhandlers +package com.github.connorwyatt.common.eventstore.eventhandlers -import io.connorwyatt.common.eventstore.events.Event -import io.connorwyatt.common.eventstore.events.EventMetadata -import io.connorwyatt.common.eventstore.streams.StreamDescriptor +import com.github.connorwyatt.common.eventstore.events.Event +import com.github.connorwyatt.common.eventstore.events.EventMetadata +import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor import kotlin.reflect.KClass import kotlin.reflect.full.findAnnotation diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/EventHandlerDefinition.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/EventHandlerDefinition.kt similarity index 54% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/EventHandlerDefinition.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/EventHandlerDefinition.kt index c5bddd2..02a0247 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/EventHandlerDefinition.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/EventHandlerDefinition.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.eventstore.eventhandlers +package com.github.connorwyatt.common.eventstore.eventhandlers -import io.connorwyatt.common.eventstore.streams.StreamDescriptor +import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor import kotlin.reflect.KClass class EventHandlerDefinition( diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/EventHandlerMap.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/EventHandlerMap.kt similarity index 78% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/EventHandlerMap.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/EventHandlerMap.kt index dd74e7b..d9f0f11 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/EventHandlerMap.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/EventHandlerMap.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.eventstore.eventhandlers +package com.github.connorwyatt.common.eventstore.eventhandlers -import io.connorwyatt.common.eventstore.streams.StreamDescriptor +import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor import kotlin.reflect.KClass class EventHandlerMap(private val definitions: Set) { diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/EventStoreSubscriptionsManager.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/EventStoreSubscriptionsManager.kt similarity index 86% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/EventStoreSubscriptionsManager.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/EventStoreSubscriptionsManager.kt index 9acd38b..30a92ba 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/EventStoreSubscriptionsManager.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/EventStoreSubscriptionsManager.kt @@ -1,9 +1,9 @@ -package io.connorwyatt.common.eventstore.eventhandlers +package com.github.connorwyatt.common.eventstore.eventhandlers import com.eventstore.dbclient.SubscribeToStreamOptions -import io.connorwyatt.common.eventstore.EventStoreClientWrapper -import io.connorwyatt.common.eventstore.events.ResolvedEventMapper -import io.connorwyatt.common.eventstore.streams.StreamDescriptor +import com.github.connorwyatt.common.eventstore.EventStoreClientWrapper +import com.github.connorwyatt.common.eventstore.events.ResolvedEventMapper +import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -11,7 +11,8 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking class EventStoreSubscriptionsManager( - private val eventStoreClientWrapper: EventStoreClientWrapper, + private val eventStoreClientWrapper: + com.github.connorwyatt.common.eventstore.EventStoreClientWrapper, private val eventHandlers: Set, private val eventHandlerMap: EventHandlerMap, private val resolvedEventMapper: ResolvedEventMapper diff --git a/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/SubscriptionName.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/SubscriptionName.kt new file mode 100644 index 0000000..99145a3 --- /dev/null +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/eventhandlers/SubscriptionName.kt @@ -0,0 +1,3 @@ +package com.github.connorwyatt.common.eventstore.eventhandlers + +annotation class SubscriptionName(val name: String) diff --git a/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/Event.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/Event.kt new file mode 100644 index 0000000..2612c2b --- /dev/null +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/Event.kt @@ -0,0 +1,3 @@ +package com.github.connorwyatt.common.eventstore.events + +interface Event diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventClassDiscriminator.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventClassDiscriminator.kt similarity index 54% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventClassDiscriminator.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventClassDiscriminator.kt index 5df1a19..9ef7af6 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventClassDiscriminator.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventClassDiscriminator.kt @@ -1,3 +1,3 @@ -package io.connorwyatt.common.eventstore.events +package com.github.connorwyatt.common.eventstore.events internal const val EVENT_CLASS_DISCRIMINATOR = "${'$'}${'$'}type" diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventEnvelope.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventEnvelope.kt similarity index 61% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventEnvelope.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventEnvelope.kt index b4f79c1..d76d970 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventEnvelope.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventEnvelope.kt @@ -1,3 +1,3 @@ -package io.connorwyatt.common.eventstore.events +package com.github.connorwyatt.common.eventstore.events data class EventEnvelope(val event: TEvent, val metadata: EventMetadata) diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventJson.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventJson.kt similarity index 89% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventJson.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventJson.kt index cedd962..4ee6ba6 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventJson.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventJson.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.eventstore.events +package com.github.connorwyatt.common.eventstore.events import kotlinx.serialization.* import kotlinx.serialization.json.* diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventMap.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventMap.kt similarity index 95% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventMap.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventMap.kt index 0e11a13..5ddbb5b 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventMap.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventMap.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.eventstore.events +package com.github.connorwyatt.common.eventstore.events import kotlin.reflect.KClass diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventMapDefinition.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventMapDefinition.kt similarity index 73% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventMapDefinition.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventMapDefinition.kt index 0518f0c..9b5dc58 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventMapDefinition.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventMapDefinition.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.eventstore.events +package com.github.connorwyatt.common.eventstore.events import kotlin.reflect.KClass diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventMetadata.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventMetadata.kt similarity index 90% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventMetadata.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventMetadata.kt index e413716..8c816c1 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventMetadata.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventMetadata.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.eventstore.events +package com.github.connorwyatt.common.eventstore.events import com.eventstore.dbclient.ResolvedEvent import java.time.Instant diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventStoreEventsRepository.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventStoreEventsRepository.kt similarity index 72% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventStoreEventsRepository.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventStoreEventsRepository.kt index 8d378b2..34c5a0a 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventStoreEventsRepository.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventStoreEventsRepository.kt @@ -1,14 +1,14 @@ -package io.connorwyatt.common.eventstore.events +package com.github.connorwyatt.common.eventstore.events import com.eventstore.dbclient.AppendToStreamOptions import com.eventstore.dbclient.EventDataBuilder import com.eventstore.dbclient.ExpectedRevision import com.eventstore.dbclient.ReadStreamOptions -import io.connorwyatt.common.eventstore.EventStoreClientWrapper -import io.connorwyatt.common.eventstore.streams.StreamDescriptor +import com.github.connorwyatt.common.eventstore.EventStoreClientWrapper +import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor class EventStoreEventsRepository( - private val eventStoreClient: EventStoreClientWrapper, + private val eventStoreClient: com.github.connorwyatt.common.eventstore.EventStoreClientWrapper, private val eventMap: EventMap, private val resolvedEventMapper: ResolvedEventMapper ) : EventsRepository { @@ -18,8 +18,9 @@ class EventStoreEventsRepository( val result = eventStoreClient.readStream(streamDescriptor, readStreamOptions) return when (result) { - is EventStoreClientWrapper.ReadResult.Failure -> emptyList() - is EventStoreClientWrapper.ReadResult.Success -> + is com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.ReadResult.Failure -> + emptyList() + is com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.ReadResult.Success -> result.events.map(resolvedEventMapper::map) } } @@ -47,7 +48,12 @@ class EventStoreEventsRepository( val result = eventStoreClient.appendToStream(streamDescriptor, options, eventDataList) - if (result is EventStoreClientWrapper.WriteResult.Failure) throw result.exception + if ( + result + is + com.github.connorwyatt.common.eventstore.EventStoreClientWrapper.WriteResult.Failure + ) + throw result.exception } companion object { diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventTransformingSerializer.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventTransformingSerializer.kt similarity index 87% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventTransformingSerializer.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventTransformingSerializer.kt index e2b1356..89f71ef 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventTransformingSerializer.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventTransformingSerializer.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.eventstore.events +package com.github.connorwyatt.common.eventstore.events import kotlinx.serialization.* import kotlinx.serialization.json.* diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventsRepository.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventsRepository.kt similarity index 68% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventsRepository.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventsRepository.kt index ea65cae..0449b92 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/EventsRepository.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/EventsRepository.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.eventstore.events +package com.github.connorwyatt.common.eventstore.events -import io.connorwyatt.common.eventstore.streams.StreamDescriptor +import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor interface EventsRepository { suspend fun readStream(streamDescriptor: StreamDescriptor): List> diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/InMemoryEventsRepository.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/InMemoryEventsRepository.kt similarity index 94% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/InMemoryEventsRepository.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/InMemoryEventsRepository.kt index f6e3ace..1ba559b 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/InMemoryEventsRepository.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/InMemoryEventsRepository.kt @@ -1,9 +1,9 @@ -package io.connorwyatt.common.eventstore.events +package com.github.connorwyatt.common.eventstore.events -import io.connorwyatt.common.eventstore.eventhandlers.EventHandler -import io.connorwyatt.common.eventstore.eventhandlers.EventHandlerMap -import io.connorwyatt.common.eventstore.streams.StreamDescriptor -import io.connorwyatt.common.time.clock.Clock +import com.github.connorwyatt.common.eventstore.eventhandlers.EventHandler +import com.github.connorwyatt.common.eventstore.eventhandlers.EventHandlerMap +import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor +import com.github.connorwyatt.common.time.clock.Clock import java.time.Duration import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/ResolvedEventMapper.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/ResolvedEventMapper.kt similarity index 91% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/ResolvedEventMapper.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/ResolvedEventMapper.kt index ab9257c..85aa8fe 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/ResolvedEventMapper.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/ResolvedEventMapper.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.eventstore.events +package com.github.connorwyatt.common.eventstore.events import com.eventstore.dbclient.ResolvedEvent import kotlinx.serialization.* diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/VersionedEventType.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/VersionedEventType.kt similarity index 90% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/VersionedEventType.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/VersionedEventType.kt index 19f8eb6..cc5c35c 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/VersionedEventType.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/events/VersionedEventType.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.eventstore.events +package com.github.connorwyatt.common.eventstore.events data class VersionedEventType(val name: String, val version: Int) { override fun toString() = "$name.v$version" diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/kodein/DIBuilderExt.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/kodein/DIBuilderExt.kt similarity index 63% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/kodein/DIBuilderExt.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/kodein/DIBuilderExt.kt index 511db5e..7bb6909 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/kodein/DIBuilderExt.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/kodein/DIBuilderExt.kt @@ -1,13 +1,13 @@ -package io.connorwyatt.common.eventstore.kodein +package com.github.connorwyatt.common.eventstore.kodein -import io.connorwyatt.common.eventstore.aggregates.Aggregate -import io.connorwyatt.common.eventstore.aggregates.AggregateMapDefinition -import io.connorwyatt.common.eventstore.eventhandlers.EventHandler -import io.connorwyatt.common.eventstore.eventhandlers.EventHandlerDefinition -import io.connorwyatt.common.eventstore.events.Event -import io.connorwyatt.common.eventstore.events.EventMapDefinition -import io.connorwyatt.common.eventstore.events.VersionedEventType -import io.connorwyatt.common.eventstore.streams.StreamDescriptor +import com.github.connorwyatt.common.eventstore.aggregates.Aggregate +import com.github.connorwyatt.common.eventstore.aggregates.AggregateMapDefinition +import com.github.connorwyatt.common.eventstore.eventhandlers.EventHandler +import com.github.connorwyatt.common.eventstore.eventhandlers.EventHandlerDefinition +import com.github.connorwyatt.common.eventstore.events.Event +import com.github.connorwyatt.common.eventstore.events.EventMapDefinition +import com.github.connorwyatt.common.eventstore.events.VersionedEventType +import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor import org.kodein.di.* import org.kodein.di.bindings.* diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/kodein/EventStoreDependenciesModule.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/kodein/EventStoreDependenciesModule.kt similarity index 53% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/kodein/EventStoreDependenciesModule.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/kodein/EventStoreDependenciesModule.kt index d6e0d09..2924bd1 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/kodein/EventStoreDependenciesModule.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/kodein/EventStoreDependenciesModule.kt @@ -1,23 +1,23 @@ -package io.connorwyatt.common.eventstore.kodein +package com.github.connorwyatt.common.eventstore.kodein import com.eventstore.dbclient.EventStoreDBClient import com.eventstore.dbclient.EventStoreDBConnectionString -import io.connorwyatt.common.eventstore.EventStoreClientWrapper -import io.connorwyatt.common.eventstore.aggregates.Aggregate -import io.connorwyatt.common.eventstore.aggregates.AggregateMap -import io.connorwyatt.common.eventstore.aggregates.AggregateMapDefinition -import io.connorwyatt.common.eventstore.aggregates.AggregatesRepository -import io.connorwyatt.common.eventstore.configuration.EventStoreConfiguration -import io.connorwyatt.common.eventstore.eventhandlers.EventHandler -import io.connorwyatt.common.eventstore.eventhandlers.EventHandlerDefinition -import io.connorwyatt.common.eventstore.eventhandlers.EventHandlerMap -import io.connorwyatt.common.eventstore.eventhandlers.EventStoreSubscriptionsManager -import io.connorwyatt.common.eventstore.events.EventMap -import io.connorwyatt.common.eventstore.events.EventMapDefinition -import io.connorwyatt.common.eventstore.events.EventStoreEventsRepository -import io.connorwyatt.common.eventstore.events.EventsRepository -import io.connorwyatt.common.eventstore.events.InMemoryEventsRepository -import io.connorwyatt.common.eventstore.events.ResolvedEventMapper +import com.github.connorwyatt.common.eventstore.EventStoreClientWrapper +import com.github.connorwyatt.common.eventstore.aggregates.Aggregate +import com.github.connorwyatt.common.eventstore.aggregates.AggregateMap +import com.github.connorwyatt.common.eventstore.aggregates.AggregateMapDefinition +import com.github.connorwyatt.common.eventstore.aggregates.AggregatesRepository +import com.github.connorwyatt.common.eventstore.configuration.EventStoreConfiguration +import com.github.connorwyatt.common.eventstore.eventhandlers.EventHandler +import com.github.connorwyatt.common.eventstore.eventhandlers.EventHandlerDefinition +import com.github.connorwyatt.common.eventstore.eventhandlers.EventHandlerMap +import com.github.connorwyatt.common.eventstore.eventhandlers.EventStoreSubscriptionsManager +import com.github.connorwyatt.common.eventstore.events.EventMap +import com.github.connorwyatt.common.eventstore.events.EventMapDefinition +import com.github.connorwyatt.common.eventstore.events.EventStoreEventsRepository +import com.github.connorwyatt.common.eventstore.events.EventsRepository +import com.github.connorwyatt.common.eventstore.events.InMemoryEventsRepository +import com.github.connorwyatt.common.eventstore.events.ResolvedEventMapper import org.kodein.di.* fun eventStoreDependenciesModule(eventStoreConfiguration: EventStoreConfiguration): DI.Module = diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/ktor/ApplicationExt.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/ktor/ApplicationExt.kt similarity index 60% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/ktor/ApplicationExt.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/ktor/ApplicationExt.kt index f63c4f0..485b1ec 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/ktor/ApplicationExt.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/ktor/ApplicationExt.kt @@ -1,9 +1,9 @@ -package io.connorwyatt.common.eventstore.ktor +package com.github.connorwyatt.common.eventstore.ktor -import io.connorwyatt.common.eventstore.configuration.EventStoreConfiguration -import io.connorwyatt.common.eventstore.eventhandlers.EventStoreSubscriptionsManager -import io.connorwyatt.common.eventstore.events.EventsRepository -import io.connorwyatt.common.eventstore.events.InMemoryEventsRepository +import com.github.connorwyatt.common.eventstore.configuration.EventStoreConfiguration +import com.github.connorwyatt.common.eventstore.eventhandlers.EventStoreSubscriptionsManager +import com.github.connorwyatt.common.eventstore.events.EventsRepository +import com.github.connorwyatt.common.eventstore.events.InMemoryEventsRepository import io.ktor.server.application.* import org.kodein.di.instance import org.kodein.di.ktor.closestDI diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/streams/StreamConstants.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/streams/StreamConstants.kt similarity index 77% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/streams/StreamConstants.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/streams/StreamConstants.kt index 9608e4d..3222c28 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/streams/StreamConstants.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/streams/StreamConstants.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.eventstore.streams +package com.github.connorwyatt.common.eventstore.streams internal object StreamConstants { internal const val allStreamName = "\$all" diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/streams/StreamDescriptor.kt b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/streams/StreamDescriptor.kt similarity index 96% rename from eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/streams/StreamDescriptor.kt rename to eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/streams/StreamDescriptor.kt index af29d99..eff828a 100644 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/streams/StreamDescriptor.kt +++ b/eventstore/src/main/kotlin/com/github/connorwyatt/common/eventstore/streams/StreamDescriptor.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.eventstore.streams +package com.github.connorwyatt.common.eventstore.streams -import io.connorwyatt.common.eventstore.events.VersionedEventType +import com.github.connorwyatt.common.eventstore.events.VersionedEventType abstract class StreamDescriptor { abstract val streamName: String diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/SubscriptionName.kt b/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/SubscriptionName.kt deleted file mode 100644 index 1ce91e4..0000000 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/eventhandlers/SubscriptionName.kt +++ /dev/null @@ -1,3 +0,0 @@ -package io.connorwyatt.common.eventstore.eventhandlers - -annotation class SubscriptionName(val name: String) diff --git a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/Event.kt b/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/Event.kt deleted file mode 100644 index 4c77321..0000000 --- a/eventstore/src/main/kotlin/io/connorwyatt/common/eventstore/events/Event.kt +++ /dev/null @@ -1,3 +0,0 @@ -package io.connorwyatt.common.eventstore.events - -interface Event diff --git a/eventstore/src/test/kotlin/io/connorwyatt/common/eventstore/streams/StreamDescriptorTests.kt b/eventstore/src/test/kotlin/com/github/connorwyatt/common/eventstore/streams/StreamDescriptorTests.kt similarity index 93% rename from eventstore/src/test/kotlin/io/connorwyatt/common/eventstore/streams/StreamDescriptorTests.kt rename to eventstore/src/test/kotlin/com/github/connorwyatt/common/eventstore/streams/StreamDescriptorTests.kt index af9b3b5..eddff85 100644 --- a/eventstore/src/test/kotlin/io/connorwyatt/common/eventstore/streams/StreamDescriptorTests.kt +++ b/eventstore/src/test/kotlin/com/github/connorwyatt/common/eventstore/streams/StreamDescriptorTests.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.eventstore.streams +package com.github.connorwyatt.common.eventstore.streams -import io.connorwyatt.common.eventstore.events.VersionedEventType +import com.github.connorwyatt.common.eventstore.events.VersionedEventType import java.util.stream.Stream import org.junit.jupiter.api.extension.ExtensionContext import org.junit.jupiter.params.ParameterizedTest diff --git a/http/src/main/kotlin/io/connorwyatt/common/http/BaseHttpResult.kt b/http/src/main/kotlin/com/github/connorwyatt/common/http/BaseHttpResult.kt similarity index 75% rename from http/src/main/kotlin/io/connorwyatt/common/http/BaseHttpResult.kt rename to http/src/main/kotlin/com/github/connorwyatt/common/http/BaseHttpResult.kt index 12e4fcc..2a7a9a0 100644 --- a/http/src/main/kotlin/io/connorwyatt/common/http/BaseHttpResult.kt +++ b/http/src/main/kotlin/com/github/connorwyatt/common/http/BaseHttpResult.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.http +package com.github.connorwyatt.common.http import io.ktor.client.statement.* diff --git a/http/src/main/kotlin/io/connorwyatt/common/http/EmptyHttpResult.kt b/http/src/main/kotlin/com/github/connorwyatt/common/http/EmptyHttpResult.kt similarity index 84% rename from http/src/main/kotlin/io/connorwyatt/common/http/EmptyHttpResult.kt rename to http/src/main/kotlin/com/github/connorwyatt/common/http/EmptyHttpResult.kt index 7a444db..adbe279 100644 --- a/http/src/main/kotlin/io/connorwyatt/common/http/EmptyHttpResult.kt +++ b/http/src/main/kotlin/com/github/connorwyatt/common/http/EmptyHttpResult.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.http +package com.github.connorwyatt.common.http import io.ktor.client.statement.* diff --git a/http/src/main/kotlin/io/connorwyatt/common/http/HttpDependenciesModule.kt b/http/src/main/kotlin/com/github/connorwyatt/common/http/HttpDependenciesModule.kt similarity index 86% rename from http/src/main/kotlin/io/connorwyatt/common/http/HttpDependenciesModule.kt rename to http/src/main/kotlin/com/github/connorwyatt/common/http/HttpDependenciesModule.kt index 95becb4..a13f85f 100644 --- a/http/src/main/kotlin/io/connorwyatt/common/http/HttpDependenciesModule.kt +++ b/http/src/main/kotlin/com/github/connorwyatt/common/http/HttpDependenciesModule.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.http +package com.github.connorwyatt.common.http import io.ktor.client.* import io.ktor.client.engine.cio.* diff --git a/http/src/main/kotlin/io/connorwyatt/common/http/HttpResult.kt b/http/src/main/kotlin/com/github/connorwyatt/common/http/HttpResult.kt similarity index 90% rename from http/src/main/kotlin/io/connorwyatt/common/http/HttpResult.kt rename to http/src/main/kotlin/com/github/connorwyatt/common/http/HttpResult.kt index 6c68f2b..aec18ce 100644 --- a/http/src/main/kotlin/io/connorwyatt/common/http/HttpResult.kt +++ b/http/src/main/kotlin/com/github/connorwyatt/common/http/HttpResult.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.http +package com.github.connorwyatt.common.http import io.ktor.client.call.* import io.ktor.client.statement.* diff --git a/http/src/main/kotlin/io/connorwyatt/common/http/validation/ProblemResponse.kt b/http/src/main/kotlin/com/github/connorwyatt/common/http/validation/ProblemResponse.kt similarity index 68% rename from http/src/main/kotlin/io/connorwyatt/common/http/validation/ProblemResponse.kt rename to http/src/main/kotlin/com/github/connorwyatt/common/http/validation/ProblemResponse.kt index fc61568..065e4b9 100644 --- a/http/src/main/kotlin/io/connorwyatt/common/http/validation/ProblemResponse.kt +++ b/http/src/main/kotlin/com/github/connorwyatt/common/http/validation/ProblemResponse.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.http.validation +package com.github.connorwyatt.common.http.validation interface ProblemResponse { val type: String diff --git a/http/src/main/kotlin/io/connorwyatt/common/http/validation/ValidationProblemResponse.kt b/http/src/main/kotlin/com/github/connorwyatt/common/http/validation/ValidationProblemResponse.kt similarity index 88% rename from http/src/main/kotlin/io/connorwyatt/common/http/validation/ValidationProblemResponse.kt rename to http/src/main/kotlin/com/github/connorwyatt/common/http/validation/ValidationProblemResponse.kt index 1ec2390..fa10500 100644 --- a/http/src/main/kotlin/io/connorwyatt/common/http/validation/ValidationProblemResponse.kt +++ b/http/src/main/kotlin/com/github/connorwyatt/common/http/validation/ValidationProblemResponse.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.http.validation +package com.github.connorwyatt.common.http.validation import kotlinx.serialization.* diff --git a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/CollectionName.kt b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/CollectionName.kt similarity index 85% rename from mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/CollectionName.kt rename to mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/CollectionName.kt index e8797fd..987d2ab 100644 --- a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/CollectionName.kt +++ b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/CollectionName.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.mongodb +package com.github.connorwyatt.common.mongodb import kotlin.reflect.full.findAnnotation diff --git a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/MongoDBCollectionDefinition.kt b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/MongoDBCollectionDefinition.kt similarity index 62% rename from mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/MongoDBCollectionDefinition.kt rename to mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/MongoDBCollectionDefinition.kt index 69f559a..3bb3139 100644 --- a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/MongoDBCollectionDefinition.kt +++ b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/MongoDBCollectionDefinition.kt @@ -1,3 +1,3 @@ -package io.connorwyatt.common.mongodb +package com.github.connorwyatt.common.mongodb data class MongoDBCollectionDefinition(internal val collectionName: String) diff --git a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/MongoDBInitializer.kt b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/MongoDBInitializer.kt similarity index 93% rename from mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/MongoDBInitializer.kt rename to mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/MongoDBInitializer.kt index d1e3d24..1b7e319 100644 --- a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/MongoDBInitializer.kt +++ b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/MongoDBInitializer.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.mongodb +package com.github.connorwyatt.common.mongodb import com.mongodb.kotlin.client.coroutine.MongoClient import kotlinx.coroutines.CoroutineScope diff --git a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/configuration/MongoDBConfiguration.kt b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/configuration/MongoDBConfiguration.kt similarity index 62% rename from mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/configuration/MongoDBConfiguration.kt rename to mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/configuration/MongoDBConfiguration.kt index 644dcc3..c816ffd 100644 --- a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/configuration/MongoDBConfiguration.kt +++ b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/configuration/MongoDBConfiguration.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.mongodb.configuration +package com.github.connorwyatt.common.mongodb.configuration data class MongoDBConfiguration( val connectionString: String?, diff --git a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/kodein/DIBuilderExt.kt b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/kodein/DIBuilderExt.kt similarity index 53% rename from mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/kodein/DIBuilderExt.kt rename to mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/kodein/DIBuilderExt.kt index c30efa4..48ca9ad 100644 --- a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/kodein/DIBuilderExt.kt +++ b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/kodein/DIBuilderExt.kt @@ -1,7 +1,7 @@ -package io.connorwyatt.common.mongodb.kodein +package com.github.connorwyatt.common.mongodb.kodein -import io.connorwyatt.common.mongodb.MongoDBCollectionDefinition -import io.connorwyatt.common.mongodb.collectionName +import com.github.connorwyatt.common.mongodb.MongoDBCollectionDefinition +import com.github.connorwyatt.common.mongodb.collectionName import org.kodein.di.* inline fun DI.Builder.bindMongoDBCollection() { diff --git a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/kodein/MongoDBDependenciesModule.kt b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/kodein/MongoDBDependenciesModule.kt similarity index 67% rename from mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/kodein/MongoDBDependenciesModule.kt rename to mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/kodein/MongoDBDependenciesModule.kt index 1115f9e..e1b8f19 100644 --- a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/kodein/MongoDBDependenciesModule.kt +++ b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/kodein/MongoDBDependenciesModule.kt @@ -1,9 +1,9 @@ -package io.connorwyatt.common.mongodb.kodein +package com.github.connorwyatt.common.mongodb.kodein +import com.github.connorwyatt.common.mongodb.MongoDBCollectionDefinition +import com.github.connorwyatt.common.mongodb.MongoDBInitializer +import com.github.connorwyatt.common.mongodb.configuration.MongoDBConfiguration import com.mongodb.kotlin.client.coroutine.MongoClient -import io.connorwyatt.common.mongodb.MongoDBCollectionDefinition -import io.connorwyatt.common.mongodb.MongoDBInitializer -import io.connorwyatt.common.mongodb.configuration.MongoDBConfiguration import org.kodein.di.* fun mongoDBDependenciesModule(mongoDBConfiguration: MongoDBConfiguration): DI.Module = diff --git a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/ktor/ApplicationExt.kt b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/ktor/ApplicationExt.kt similarity index 70% rename from mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/ktor/ApplicationExt.kt rename to mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/ktor/ApplicationExt.kt index 1600b6e..b2c3b92 100644 --- a/mongodb/src/main/kotlin/io/connorwyatt/common/mongodb/ktor/ApplicationExt.kt +++ b/mongodb/src/main/kotlin/com/github/connorwyatt/common/mongodb/ktor/ApplicationExt.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.mongodb.ktor +package com.github.connorwyatt.common.mongodb.ktor -import io.connorwyatt.common.mongodb.MongoDBInitializer +import com.github.connorwyatt.common.mongodb.MongoDBInitializer import io.ktor.server.application.* import org.kodein.di.instanceOrNull import org.kodein.di.ktor.closestDI diff --git a/optional/src/main/kotlin/io/connorwyatt/common/optional/Optional.kt b/optional/src/main/kotlin/com/github/connorwyatt/common/optional/Optional.kt similarity index 83% rename from optional/src/main/kotlin/io/connorwyatt/common/optional/Optional.kt rename to optional/src/main/kotlin/com/github/connorwyatt/common/optional/Optional.kt index 2d45729..1ee67d1 100644 --- a/optional/src/main/kotlin/io/connorwyatt/common/optional/Optional.kt +++ b/optional/src/main/kotlin/com/github/connorwyatt/common/optional/Optional.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.optional +package com.github.connorwyatt.common.optional -import io.connorwyatt.common.optional.serialization.OptionalSerializer +import com.github.connorwyatt.common.optional.serialization.OptionalSerializer import kotlinx.serialization.* /** diff --git a/optional/src/main/kotlin/io/connorwyatt/common/optional/serialization/OptionalSerializer.kt b/optional/src/main/kotlin/com/github/connorwyatt/common/optional/serialization/OptionalSerializer.kt similarity index 83% rename from optional/src/main/kotlin/io/connorwyatt/common/optional/serialization/OptionalSerializer.kt rename to optional/src/main/kotlin/com/github/connorwyatt/common/optional/serialization/OptionalSerializer.kt index 924bd76..ee11d65 100644 --- a/optional/src/main/kotlin/io/connorwyatt/common/optional/serialization/OptionalSerializer.kt +++ b/optional/src/main/kotlin/com/github/connorwyatt/common/optional/serialization/OptionalSerializer.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.optional.serialization +package com.github.connorwyatt.common.optional.serialization -import io.connorwyatt.common.optional.Optional +import com.github.connorwyatt.common.optional.Optional import kotlinx.serialization.* import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.* diff --git a/optional/src/test/kotlin/io/connorwyatt/common/optional/serialization/OptionalSerializerTests.kt b/optional/src/test/kotlin/com/github/connorwyatt/common/optional/serialization/OptionalSerializerTests.kt similarity index 94% rename from optional/src/test/kotlin/io/connorwyatt/common/optional/serialization/OptionalSerializerTests.kt rename to optional/src/test/kotlin/com/github/connorwyatt/common/optional/serialization/OptionalSerializerTests.kt index 8bf4a6c..a966a80 100644 --- a/optional/src/test/kotlin/io/connorwyatt/common/optional/serialization/OptionalSerializerTests.kt +++ b/optional/src/test/kotlin/com/github/connorwyatt/common/optional/serialization/OptionalSerializerTests.kt @@ -1,7 +1,7 @@ -package io.connorwyatt.common.optional.serialization +package com.github.connorwyatt.common.optional.serialization -import io.connorwyatt.common.optional.Optional -import io.connorwyatt.common.optional.Optional.* +import com.github.connorwyatt.common.optional.Optional +import com.github.connorwyatt.common.optional.Optional.* import kotlinx.serialization.* import kotlinx.serialization.json.* import org.junit.jupiter.api.Test diff --git a/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/Command.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/Command.kt new file mode 100644 index 0000000..35e3af0 --- /dev/null +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/Command.kt @@ -0,0 +1,3 @@ +package com.github.connorwyatt.common.rabbitmq + +interface Command diff --git a/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/CommandEnvelope.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/CommandEnvelope.kt new file mode 100644 index 0000000..598e6a6 --- /dev/null +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/CommandEnvelope.kt @@ -0,0 +1,3 @@ +package com.github.connorwyatt.common.rabbitmq + +data class CommandEnvelope(val command: com.github.connorwyatt.common.rabbitmq.Command) diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/CommandMap.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/CommandMap.kt similarity index 71% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/CommandMap.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/CommandMap.kt index d4583d2..500916f 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/CommandMap.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/CommandMap.kt @@ -1,13 +1,15 @@ -package io.connorwyatt.common.rabbitmq +package com.github.connorwyatt.common.rabbitmq import kotlin.reflect.KClass -internal class CommandMap(private val definitions: Set) { +internal class CommandMap( + private val definitions: Set +) { init { checkForDuplicates() } - fun typeFor(clazz: KClass) = + fun typeFor(clazz: KClass) = definitions.singleOrNull { it.clazz == clazz }?.type ?: throw Exception("Could not find Command type for class (${clazz.simpleName}).") diff --git a/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/CommandMapDefinition.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/CommandMapDefinition.kt new file mode 100644 index 0000000..f91e4f9 --- /dev/null +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/CommandMapDefinition.kt @@ -0,0 +1,8 @@ +package com.github.connorwyatt.common.rabbitmq + +import kotlin.reflect.KClass + +internal class CommandMapDefinition( + val type: String, + val clazz: KClass +) diff --git a/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/bus/CommandBus.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/bus/CommandBus.kt new file mode 100644 index 0000000..c7edeb0 --- /dev/null +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/bus/CommandBus.kt @@ -0,0 +1,9 @@ +package com.github.connorwyatt.common.rabbitmq.bus + +import com.github.connorwyatt.common.rabbitmq.CommandEnvelope + +interface CommandBus { + suspend fun send(commandEnvelope: com.github.connorwyatt.common.rabbitmq.CommandEnvelope) + + suspend fun send(commandEnvelopes: List) +} diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/bus/InMemoryCommandBus.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/bus/InMemoryCommandBus.kt similarity index 60% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/bus/InMemoryCommandBus.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/bus/InMemoryCommandBus.kt index 03573d9..c4df23c 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/bus/InMemoryCommandBus.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/bus/InMemoryCommandBus.kt @@ -1,8 +1,8 @@ -package io.connorwyatt.common.rabbitmq.bus +package com.github.connorwyatt.common.rabbitmq.bus -import io.connorwyatt.common.rabbitmq.Command -import io.connorwyatt.common.rabbitmq.CommandEnvelope -import io.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerRouter +import com.github.connorwyatt.common.rabbitmq.Command +import com.github.connorwyatt.common.rabbitmq.CommandEnvelope +import com.github.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerRouter import java.time.Duration import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -14,13 +14,18 @@ import kotlinx.coroutines.time.withTimeout class InMemoryCommandBus internal constructor(private val commandHandlerRouter: CommandHandlerRouter) : CommandBus { private val commandPropagationCoroutineScope = CoroutineScope(Dispatchers.Default) - private val commandPropagationChannel = Channel() + private val commandPropagationChannel = + Channel() - override suspend fun send(commandEnvelope: CommandEnvelope) { + override suspend fun send( + commandEnvelope: com.github.connorwyatt.common.rabbitmq.CommandEnvelope + ) { send(listOf(commandEnvelope)) } - override suspend fun send(commandEnvelopes: List) { + override suspend fun send( + commandEnvelopes: List + ) { commandEnvelopes.forEach { commandEnvelope -> enqueueCommandForPropagation(commandEnvelope) } @@ -43,13 +48,17 @@ internal constructor(private val commandHandlerRouter: CommandHandlerRouter) : C } } - private suspend fun enqueueCommandForPropagation(commandEnvelope: CommandEnvelope) { + private suspend fun enqueueCommandForPropagation( + commandEnvelope: com.github.connorwyatt.common.rabbitmq.CommandEnvelope + ) { commandPropagationCoroutineScope.launch { commandPropagationChannel.send(commandEnvelope.command) } } - private suspend fun propagateCommandToHandler(command: Command) { + private suspend fun propagateCommandToHandler( + command: com.github.connorwyatt.common.rabbitmq.Command + ) { commandHandlerRouter.handle(command) } } diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/bus/RabbitMQCommandBus.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/bus/RabbitMQCommandBus.kt similarity index 63% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/bus/RabbitMQCommandBus.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/bus/RabbitMQCommandBus.kt index 1909b5e..6cfd92d 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/bus/RabbitMQCommandBus.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/bus/RabbitMQCommandBus.kt @@ -1,12 +1,12 @@ -package io.connorwyatt.common.rabbitmq.bus +package com.github.connorwyatt.common.rabbitmq.bus +import com.github.connorwyatt.common.rabbitmq.Command +import com.github.connorwyatt.common.rabbitmq.CommandEnvelope +import com.github.connorwyatt.common.rabbitmq.CommandMap +import com.github.connorwyatt.common.rabbitmq.routing.CommandRoutingRules +import com.github.connorwyatt.common.rabbitmq.routing.RoutingKeyUtilities import com.rabbitmq.client.AMQP import com.rabbitmq.client.Connection -import io.connorwyatt.common.rabbitmq.Command -import io.connorwyatt.common.rabbitmq.CommandEnvelope -import io.connorwyatt.common.rabbitmq.CommandMap -import io.connorwyatt.common.rabbitmq.routing.CommandRoutingRules -import io.connorwyatt.common.rabbitmq.routing.RoutingKeyUtilities import kotlin.reflect.KClass import kotlinx.serialization.* import kotlinx.serialization.json.* @@ -14,20 +14,26 @@ import kotlinx.serialization.json.* internal class RabbitMQCommandBus( private val connection: Connection, private val exchangeName: String, - private val commandMap: CommandMap, + private val commandMap: com.github.connorwyatt.common.rabbitmq.CommandMap, private val commandRoutingRules: CommandRoutingRules ) : CommandBus { - override suspend fun send(commandEnvelope: CommandEnvelope) { + override suspend fun send( + commandEnvelope: com.github.connorwyatt.common.rabbitmq.CommandEnvelope + ) { send(listOf(commandEnvelope)) } - override suspend fun send(commandEnvelopes: List) { + override suspend fun send( + commandEnvelopes: List + ) { connection.createChannel().use { channel -> try { channel.txSelect() commandEnvelopes.forEach { commandEnvelope -> // TODO: Fix this. - val commandClass = commandEnvelope.command::class as KClass + val commandClass = + commandEnvelope.command::class + as KClass @OptIn(InternalSerializationApi::class) val serializer = commandClass.serializer() diff --git a/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/CommandHandler.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/CommandHandler.kt new file mode 100644 index 0000000..17d6f79 --- /dev/null +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/CommandHandler.kt @@ -0,0 +1,40 @@ +package com.github.connorwyatt.common.rabbitmq.commandhandlers + +import com.github.connorwyatt.common.rabbitmq.Command +import kotlin.reflect.KClass + +abstract class CommandHandler { + private var handlers = + mapOf< + KClass, + suspend (com.github.connorwyatt.common.rabbitmq.Command) -> Unit + >() + + protected fun handle( + commandClass: KClass, + handler: suspend (TCommand) -> Unit + ) { + @Suppress("UNCHECKED_CAST") + handlers = + handlers.plus( + commandClass as KClass to + handler as suspend (com.github.connorwyatt.common.rabbitmq.Command) -> Unit + ) + } + + protected inline fun handle( + noinline handler: suspend (TCommand) -> Unit + ) { + handle(TCommand::class, handler) + } + + internal suspend fun handleCommand( + command: com.github.connorwyatt.common.rabbitmq.Command, + ) = getHandlerOrThrow(command).invoke(command) + + private fun getHandlerOrThrow(command: com.github.connorwyatt.common.rabbitmq.Command) = + (handlers[command::class] + ?: throw Exception( + "CommandHandler has no handler for command ${command::class.simpleName}" + )) +} diff --git a/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerDefinition.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerDefinition.kt new file mode 100644 index 0000000..3005439 --- /dev/null +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerDefinition.kt @@ -0,0 +1,10 @@ +package com.github.connorwyatt.common.rabbitmq.commandhandlers + +import com.github.connorwyatt.common.rabbitmq.Command +import kotlin.reflect.KClass +import org.kodein.di.* + +internal class CommandHandlerDefinition( + val clazz: KClass, + val creator: DirectDI.() -> CommandHandler +) diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerMap.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerMap.kt similarity index 73% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerMap.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerMap.kt index aa8cb5c..46a323f 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerMap.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerMap.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.rabbitmq.commandhandlers +package com.github.connorwyatt.common.rabbitmq.commandhandlers -import io.connorwyatt.common.rabbitmq.Command +import com.github.connorwyatt.common.rabbitmq.Command import kotlin.reflect.KClass internal class CommandHandlerMap(private val definitions: Set) { @@ -8,7 +8,7 @@ internal class CommandHandlerMap(private val definitions: Set) = + internal fun creatorFor(clazz: KClass) = definitions.singleOrNull { it.clazz == clazz }?.creator ?: throw Exception( "Could not find CommandHandler creator for class (${clazz.simpleName})." diff --git a/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerRouter.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerRouter.kt new file mode 100644 index 0000000..3cfe6c1 --- /dev/null +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerRouter.kt @@ -0,0 +1,15 @@ +package com.github.connorwyatt.common.rabbitmq.commandhandlers + +import com.github.connorwyatt.common.rabbitmq.Command +import kotlin.reflect.KClass + +internal class CommandHandlerRouter( + private val factory: + (KClass) -> CommandHandler +) { + internal suspend fun handle(command: com.github.connorwyatt.common.rabbitmq.Command) { + val commandClass = command::class + val commandHandler = factory(commandClass) + commandHandler.handleCommand(command) + } +} diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/RabbitMQSubscriptionsManager.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/RabbitMQSubscriptionsManager.kt similarity index 81% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/RabbitMQSubscriptionsManager.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/RabbitMQSubscriptionsManager.kt index 8ac90fd..478e09b 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/RabbitMQSubscriptionsManager.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/commandhandlers/RabbitMQSubscriptionsManager.kt @@ -1,12 +1,12 @@ -package io.connorwyatt.common.rabbitmq.commandhandlers +package com.github.connorwyatt.common.rabbitmq.commandhandlers +import com.github.connorwyatt.common.rabbitmq.Command +import com.github.connorwyatt.common.rabbitmq.CommandMap +import com.github.connorwyatt.common.rabbitmq.queues.CommandQueueList import com.rabbitmq.client.CancelCallback import com.rabbitmq.client.Connection import com.rabbitmq.client.DeliverCallback import com.rabbitmq.client.Delivery -import io.connorwyatt.common.rabbitmq.Command -import io.connorwyatt.common.rabbitmq.CommandMap -import io.connorwyatt.common.rabbitmq.queues.CommandQueueList import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -18,7 +18,7 @@ internal class RabbitMQSubscriptionsManager( private val exchangeName: String, private val connection: Connection, private val commandQueueList: CommandQueueList, - private val commandMap: CommandMap, + private val commandMap: com.github.connorwyatt.common.rabbitmq.CommandMap, private val commandHandlerRouter: CommandHandlerRouter ) { private val coroutineScope = CoroutineScope(Dispatchers.Default) @@ -52,7 +52,9 @@ internal class RabbitMQSubscriptionsManager( } } - private fun deserializeCommand(message: Delivery): Command { + private fun deserializeCommand( + message: Delivery + ): com.github.connorwyatt.common.rabbitmq.Command { @OptIn(InternalSerializationApi::class) val serializer = commandMap.classFor(message.properties.type).serializer() return Json.decodeFromString(serializer, message.body.decodeToString()) diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/configuration/RabbitMQConfiguration.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/configuration/RabbitMQConfiguration.kt similarity index 69% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/configuration/RabbitMQConfiguration.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/configuration/RabbitMQConfiguration.kt index 819b9fc..506ac32 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/configuration/RabbitMQConfiguration.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/configuration/RabbitMQConfiguration.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.rabbitmq.configuration +package com.github.connorwyatt.common.rabbitmq.configuration data class RabbitMQConfiguration( val useInMemoryRabbitMQ: Boolean, diff --git a/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/kodein/DIBuilderExt.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/kodein/DIBuilderExt.kt new file mode 100644 index 0000000..f524866 --- /dev/null +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/kodein/DIBuilderExt.kt @@ -0,0 +1,48 @@ +package com.github.connorwyatt.common.rabbitmq.kodein + +import com.github.connorwyatt.common.rabbitmq.Command +import com.github.connorwyatt.common.rabbitmq.CommandMapDefinition +import com.github.connorwyatt.common.rabbitmq.commandhandlers.CommandHandler +import com.github.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerDefinition +import com.github.connorwyatt.common.rabbitmq.queues.CommandQueueDefinition +import com.github.connorwyatt.common.rabbitmq.routing.CommandRoutingRulesBuilder +import kotlin.reflect.KClass +import org.kodein.di.* + +fun DI.Builder.bindCommandQueueDefinition(queueName: String) { + inBindSet { add { singleton { CommandQueueDefinition(queueName) } } } +} + +fun DI.Builder.bindCommandDefinition( + type: String, + clazz: KClass +) { + inBindSet { add { singleton { CommandMapDefinition(type, clazz) } } } +} + +inline fun DI.Builder + .bindCommandDefinition(type: String) { + bindCommandDefinition(type, TCommand::class) +} + +fun DI.Builder.bindCommandHandler( + constructor: DirectDI.() -> CommandHandler, + clazz: KClass +) { + inBindSet { + add { singleton { CommandHandlerDefinition(clazz, constructor) } } + } +} + +inline fun DI.Builder + .bindCommandHandler(noinline constructor: DirectDI.() -> CommandHandler) { + bindCommandHandler(constructor, TCommand::class) +} + +fun DI.Builder.bindCommandRoutingRules(function: CommandRoutingRulesBuilder.() -> Unit) { + val builder = CommandRoutingRulesBuilder() + + function(builder) + + bindSingleton { builder.build() } +} diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/kodein/RabbitMQDependenciesModule.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/kodein/RabbitMQDependenciesModule.kt similarity index 63% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/kodein/RabbitMQDependenciesModule.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/kodein/RabbitMQDependenciesModule.kt index 8f0f52f..7e59952 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/kodein/RabbitMQDependenciesModule.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/kodein/RabbitMQDependenciesModule.kt @@ -1,21 +1,21 @@ -package io.connorwyatt.common.rabbitmq.kodein +package com.github.connorwyatt.common.rabbitmq.kodein +import com.github.connorwyatt.common.rabbitmq.CommandMap +import com.github.connorwyatt.common.rabbitmq.CommandMapDefinition +import com.github.connorwyatt.common.rabbitmq.bus.CommandBus +import com.github.connorwyatt.common.rabbitmq.bus.InMemoryCommandBus +import com.github.connorwyatt.common.rabbitmq.bus.RabbitMQCommandBus +import com.github.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerDefinition +import com.github.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerMap +import com.github.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerRouter +import com.github.connorwyatt.common.rabbitmq.commandhandlers.RabbitMQSubscriptionsManager +import com.github.connorwyatt.common.rabbitmq.configuration.RabbitMQConfiguration +import com.github.connorwyatt.common.rabbitmq.queues.CommandQueueCreator +import com.github.connorwyatt.common.rabbitmq.queues.CommandQueueDefinition +import com.github.connorwyatt.common.rabbitmq.queues.CommandQueueList +import com.github.connorwyatt.common.rabbitmq.queues.NoopCommandQueueCreator +import com.github.connorwyatt.common.rabbitmq.queues.RabbitMQCommandQueueCreator import com.rabbitmq.client.ConnectionFactory -import io.connorwyatt.common.rabbitmq.CommandMap -import io.connorwyatt.common.rabbitmq.CommandMapDefinition -import io.connorwyatt.common.rabbitmq.bus.CommandBus -import io.connorwyatt.common.rabbitmq.bus.InMemoryCommandBus -import io.connorwyatt.common.rabbitmq.bus.RabbitMQCommandBus -import io.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerDefinition -import io.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerMap -import io.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerRouter -import io.connorwyatt.common.rabbitmq.commandhandlers.RabbitMQSubscriptionsManager -import io.connorwyatt.common.rabbitmq.configuration.RabbitMQConfiguration -import io.connorwyatt.common.rabbitmq.queues.CommandQueueCreator -import io.connorwyatt.common.rabbitmq.queues.CommandQueueDefinition -import io.connorwyatt.common.rabbitmq.queues.CommandQueueList -import io.connorwyatt.common.rabbitmq.queues.NoopCommandQueueCreator -import io.connorwyatt.common.rabbitmq.queues.RabbitMQCommandQueueCreator import org.kodein.di.* fun rabbitMQDependenciesModule(rabbitMQConfiguration: RabbitMQConfiguration): DI.Module = diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/ktor/ApplicationExt.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/ktor/ApplicationExt.kt similarity index 62% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/ktor/ApplicationExt.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/ktor/ApplicationExt.kt index caea4bd..13168b3 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/ktor/ApplicationExt.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/ktor/ApplicationExt.kt @@ -1,10 +1,10 @@ -package io.connorwyatt.common.rabbitmq.ktor +package com.github.connorwyatt.common.rabbitmq.ktor -import io.connorwyatt.common.rabbitmq.bus.CommandBus -import io.connorwyatt.common.rabbitmq.bus.InMemoryCommandBus -import io.connorwyatt.common.rabbitmq.commandhandlers.RabbitMQSubscriptionsManager -import io.connorwyatt.common.rabbitmq.configuration.RabbitMQConfiguration -import io.connorwyatt.common.rabbitmq.queues.CommandQueueCreator +import com.github.connorwyatt.common.rabbitmq.bus.CommandBus +import com.github.connorwyatt.common.rabbitmq.bus.InMemoryCommandBus +import com.github.connorwyatt.common.rabbitmq.commandhandlers.RabbitMQSubscriptionsManager +import com.github.connorwyatt.common.rabbitmq.configuration.RabbitMQConfiguration +import com.github.connorwyatt.common.rabbitmq.queues.CommandQueueCreator import io.ktor.server.application.* import kotlinx.coroutines.launch import org.kodein.di.instance diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/CommandQueueCreator.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/CommandQueueCreator.kt similarity index 58% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/CommandQueueCreator.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/CommandQueueCreator.kt index d22a150..6af864f 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/CommandQueueCreator.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/CommandQueueCreator.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.rabbitmq.queues +package com.github.connorwyatt.common.rabbitmq.queues internal interface CommandQueueCreator { suspend fun createQueues() diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/CommandQueueDefinition.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/CommandQueueDefinition.kt similarity index 53% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/CommandQueueDefinition.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/CommandQueueDefinition.kt index cfe70b6..a6814f4 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/CommandQueueDefinition.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/CommandQueueDefinition.kt @@ -1,3 +1,3 @@ -package io.connorwyatt.common.rabbitmq.queues +package com.github.connorwyatt.common.rabbitmq.queues internal data class CommandQueueDefinition(val name: String) diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/CommandQueueList.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/CommandQueueList.kt similarity index 60% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/CommandQueueList.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/CommandQueueList.kt index 44c9415..6442d7b 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/CommandQueueList.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/CommandQueueList.kt @@ -1,3 +1,3 @@ -package io.connorwyatt.common.rabbitmq.queues +package com.github.connorwyatt.common.rabbitmq.queues internal data class CommandQueueList(val definitions: Set) diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/NoopCommandQueueCreator.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/NoopCommandQueueCreator.kt similarity index 66% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/NoopCommandQueueCreator.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/NoopCommandQueueCreator.kt index 8065c82..dd15f7a 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/NoopCommandQueueCreator.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/NoopCommandQueueCreator.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.rabbitmq.queues +package com.github.connorwyatt.common.rabbitmq.queues internal class NoopCommandQueueCreator : CommandQueueCreator { override suspend fun createQueues() {} diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/RabbitMQCommandQueueCreator.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/RabbitMQCommandQueueCreator.kt similarity index 93% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/RabbitMQCommandQueueCreator.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/RabbitMQCommandQueueCreator.kt index 79f9668..c16297b 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/queues/RabbitMQCommandQueueCreator.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/queues/RabbitMQCommandQueueCreator.kt @@ -1,8 +1,8 @@ -package io.connorwyatt.common.rabbitmq.queues +package com.github.connorwyatt.common.rabbitmq.queues +import com.github.connorwyatt.common.rabbitmq.routing.RoutingKeyUtilities import com.rabbitmq.client.Channel import com.rabbitmq.client.Connection -import io.connorwyatt.common.rabbitmq.routing.RoutingKeyUtilities import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.joinAll diff --git a/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/routing/CommandRoutingRules.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/routing/CommandRoutingRules.kt new file mode 100644 index 0000000..4fcc2ec --- /dev/null +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/routing/CommandRoutingRules.kt @@ -0,0 +1,12 @@ +package com.github.connorwyatt.common.rabbitmq.routing + +import com.github.connorwyatt.common.rabbitmq.Command +import kotlin.reflect.KClass + +internal data class CommandRoutingRules( + private val defaultQueueName: String, + private val rules: Map, String> +) { + fun queueFor(clazz: KClass): String = + rules[clazz] ?: defaultQueueName +} diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/routing/CommandRoutingRulesBuilder.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/routing/CommandRoutingRulesBuilder.kt similarity index 61% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/routing/CommandRoutingRulesBuilder.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/routing/CommandRoutingRulesBuilder.kt index 075dfab..2bbb518 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/routing/CommandRoutingRulesBuilder.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/routing/CommandRoutingRulesBuilder.kt @@ -1,11 +1,12 @@ -package io.connorwyatt.common.rabbitmq.routing +package com.github.connorwyatt.common.rabbitmq.routing -import io.connorwyatt.common.rabbitmq.Command +import com.github.connorwyatt.common.rabbitmq.Command import kotlin.reflect.KClass class CommandRoutingRulesBuilder internal constructor() { private var defaultQueueName: String? = null - private var rules = emptyMap, String>() + private var rules = + emptyMap, String>() fun defaultQueue(queueName: String) { if (defaultQueueName != null) { @@ -15,7 +16,10 @@ class CommandRoutingRulesBuilder internal constructor() { defaultQueueName = queueName } - fun queueFor(clazz: KClass, queueName: String) { + fun queueFor( + clazz: KClass, + queueName: String + ) { if (rules.containsKey(clazz)) { throw Exception("Already registered queue for ${clazz.simpleName}.") } @@ -23,7 +27,9 @@ class CommandRoutingRulesBuilder internal constructor() { rules = rules.plus(clazz to queueName) } - inline fun queueFor(queueName: String) { + inline fun queueFor( + queueName: String + ) { queueFor(TCommand::class, queueName) } diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/routing/RoutingKeyUtilities.kt b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/routing/RoutingKeyUtilities.kt similarity index 66% rename from rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/routing/RoutingKeyUtilities.kt rename to rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/routing/RoutingKeyUtilities.kt index 51e62bd..a642c4b 100644 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/routing/RoutingKeyUtilities.kt +++ b/rabbitmq/src/main/kotlin/com/github/connorwyatt/common/rabbitmq/routing/RoutingKeyUtilities.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.rabbitmq.routing +package com.github.connorwyatt.common.rabbitmq.routing internal object RoutingKeyUtilities { fun routingKeyFor(queueName: String) = "$queueName.routingKey" diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/Command.kt b/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/Command.kt deleted file mode 100644 index d30bf8e..0000000 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/Command.kt +++ /dev/null @@ -1,3 +0,0 @@ -package io.connorwyatt.common.rabbitmq - -interface Command diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/CommandEnvelope.kt b/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/CommandEnvelope.kt deleted file mode 100644 index 6130e52..0000000 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/CommandEnvelope.kt +++ /dev/null @@ -1,3 +0,0 @@ -package io.connorwyatt.common.rabbitmq - -data class CommandEnvelope(val command: Command) diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/CommandMapDefinition.kt b/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/CommandMapDefinition.kt deleted file mode 100644 index 5c33a8d..0000000 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/CommandMapDefinition.kt +++ /dev/null @@ -1,5 +0,0 @@ -package io.connorwyatt.common.rabbitmq - -import kotlin.reflect.KClass - -internal class CommandMapDefinition(val type: String, val clazz: KClass) diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/bus/CommandBus.kt b/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/bus/CommandBus.kt deleted file mode 100644 index 4cb407a..0000000 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/bus/CommandBus.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.connorwyatt.common.rabbitmq.bus - -import io.connorwyatt.common.rabbitmq.CommandEnvelope - -interface CommandBus { - suspend fun send(commandEnvelope: CommandEnvelope) - - suspend fun send(commandEnvelopes: List) -} diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/CommandHandler.kt b/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/CommandHandler.kt deleted file mode 100644 index 3f64279..0000000 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/CommandHandler.kt +++ /dev/null @@ -1,35 +0,0 @@ -package io.connorwyatt.common.rabbitmq.commandhandlers - -import io.connorwyatt.common.rabbitmq.Command -import kotlin.reflect.KClass - -abstract class CommandHandler { - private var handlers = mapOf, suspend (Command) -> Unit>() - - protected fun handle( - commandClass: KClass, - handler: suspend (TCommand) -> Unit - ) { - @Suppress("UNCHECKED_CAST") - handlers = - handlers.plus( - commandClass as KClass to handler as suspend (Command) -> Unit - ) - } - - protected inline fun handle( - noinline handler: suspend (TCommand) -> Unit - ) { - handle(TCommand::class, handler) - } - - internal suspend fun handleCommand( - command: Command, - ) = getHandlerOrThrow(command).invoke(command) - - private fun getHandlerOrThrow(command: Command) = - (handlers[command::class] - ?: throw Exception( - "CommandHandler has no handler for command ${command::class.simpleName}" - )) -} diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerDefinition.kt b/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerDefinition.kt deleted file mode 100644 index 21311b1..0000000 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerDefinition.kt +++ /dev/null @@ -1,10 +0,0 @@ -package io.connorwyatt.common.rabbitmq.commandhandlers - -import io.connorwyatt.common.rabbitmq.Command -import kotlin.reflect.KClass -import org.kodein.di.* - -internal class CommandHandlerDefinition( - val clazz: KClass, - val creator: DirectDI.() -> CommandHandler -) diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerRouter.kt b/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerRouter.kt deleted file mode 100644 index f52ed5c..0000000 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/commandhandlers/CommandHandlerRouter.kt +++ /dev/null @@ -1,12 +0,0 @@ -package io.connorwyatt.common.rabbitmq.commandhandlers - -import io.connorwyatt.common.rabbitmq.Command -import kotlin.reflect.KClass - -internal class CommandHandlerRouter(private val factory: (KClass) -> CommandHandler) { - internal suspend fun handle(command: Command) { - val commandClass = command::class - val commandHandler = factory(commandClass) - commandHandler.handleCommand(command) - } -} diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/kodein/DIBuilderExt.kt b/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/kodein/DIBuilderExt.kt deleted file mode 100644 index 9ff53f0..0000000 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/kodein/DIBuilderExt.kt +++ /dev/null @@ -1,45 +0,0 @@ -package io.connorwyatt.common.rabbitmq.kodein - -import io.connorwyatt.common.rabbitmq.Command -import io.connorwyatt.common.rabbitmq.CommandMapDefinition -import io.connorwyatt.common.rabbitmq.commandhandlers.CommandHandler -import io.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerDefinition -import io.connorwyatt.common.rabbitmq.queues.CommandQueueDefinition -import io.connorwyatt.common.rabbitmq.routing.CommandRoutingRulesBuilder -import kotlin.reflect.KClass -import org.kodein.di.* - -fun DI.Builder.bindCommandQueueDefinition(queueName: String) { - inBindSet { add { singleton { CommandQueueDefinition(queueName) } } } -} - -fun DI.Builder.bindCommandDefinition(type: String, clazz: KClass) { - inBindSet { add { singleton { CommandMapDefinition(type, clazz) } } } -} - -inline fun DI.Builder.bindCommandDefinition(type: String) { - bindCommandDefinition(type, TCommand::class) -} - -fun DI.Builder.bindCommandHandler( - constructor: DirectDI.() -> CommandHandler, - clazz: KClass -) { - inBindSet { - add { singleton { CommandHandlerDefinition(clazz, constructor) } } - } -} - -inline fun DI.Builder.bindCommandHandler( - noinline constructor: DirectDI.() -> CommandHandler -) { - bindCommandHandler(constructor, TCommand::class) -} - -fun DI.Builder.bindCommandRoutingRules(function: CommandRoutingRulesBuilder.() -> Unit) { - val builder = CommandRoutingRulesBuilder() - - function(builder) - - bindSingleton { builder.build() } -} diff --git a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/routing/CommandRoutingRules.kt b/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/routing/CommandRoutingRules.kt deleted file mode 100644 index 8f69b7b..0000000 --- a/rabbitmq/src/main/kotlin/io/connorwyatt/common/rabbitmq/routing/CommandRoutingRules.kt +++ /dev/null @@ -1,11 +0,0 @@ -package io.connorwyatt.common.rabbitmq.routing - -import io.connorwyatt.common.rabbitmq.Command -import kotlin.reflect.KClass - -internal data class CommandRoutingRules( - private val defaultQueueName: String, - private val rules: Map, String> -) { - fun queueFor(clazz: KClass): String = rules[clazz] ?: defaultQueueName -} diff --git a/result/src/main/kotlin/io/connorwyatt/common/result/Result.kt b/result/src/main/kotlin/com/github/connorwyatt/common/result/Result.kt similarity index 89% rename from result/src/main/kotlin/io/connorwyatt/common/result/Result.kt rename to result/src/main/kotlin/com/github/connorwyatt/common/result/Result.kt index f31047e..edf5dc0 100644 --- a/result/src/main/kotlin/io/connorwyatt/common/result/Result.kt +++ b/result/src/main/kotlin/com/github/connorwyatt/common/result/Result.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.result +package com.github.connorwyatt.common.result sealed interface Result { fun getOrThrow(): TSuccess = diff --git a/result/src/test/kotlin/io/connorwyatt/common/result/ResultTests.kt b/result/src/test/kotlin/com/github/connorwyatt/common/result/ResultTests.kt similarity index 92% rename from result/src/test/kotlin/io/connorwyatt/common/result/ResultTests.kt rename to result/src/test/kotlin/com/github/connorwyatt/common/result/ResultTests.kt index c1b83e0..b2c6120 100644 --- a/result/src/test/kotlin/io/connorwyatt/common/result/ResultTests.kt +++ b/result/src/test/kotlin/com/github/connorwyatt/common/result/ResultTests.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.result +package com.github.connorwyatt.common.result import org.junit.jupiter.api.Test import strikt.api.expectThat diff --git a/server/src/main/kotlin/io/connorwyatt/common/server/ApplicationConfiguration.kt b/server/src/main/kotlin/com/github/connorwyatt/common/server/ApplicationConfiguration.kt similarity index 83% rename from server/src/main/kotlin/io/connorwyatt/common/server/ApplicationConfiguration.kt rename to server/src/main/kotlin/com/github/connorwyatt/common/server/ApplicationConfiguration.kt index dbef3a2..e4d4880 100644 --- a/server/src/main/kotlin/io/connorwyatt/common/server/ApplicationConfiguration.kt +++ b/server/src/main/kotlin/com/github/connorwyatt/common/server/ApplicationConfiguration.kt @@ -1,16 +1,16 @@ -package io.connorwyatt.common.server - -import io.connorwyatt.common.eventstore.configuration.EventStoreConfiguration -import io.connorwyatt.common.eventstore.kodein.eventStoreDependenciesModule -import io.connorwyatt.common.eventstore.ktor.configureEventStore -import io.connorwyatt.common.http.httpDependenciesModule -import io.connorwyatt.common.mongodb.configuration.MongoDBConfiguration -import io.connorwyatt.common.mongodb.kodein.mongoDBDependenciesModule -import io.connorwyatt.common.mongodb.ktor.configureMongoDB -import io.connorwyatt.common.rabbitmq.configuration.RabbitMQConfiguration -import io.connorwyatt.common.rabbitmq.kodein.rabbitMQDependenciesModule -import io.connorwyatt.common.rabbitmq.ktor.configureRabbitMQ -import io.connorwyatt.common.time.timeDependenciesModule +package com.github.connorwyatt.common.server + +import com.github.connorwyatt.common.eventstore.configuration.EventStoreConfiguration +import com.github.connorwyatt.common.eventstore.kodein.eventStoreDependenciesModule +import com.github.connorwyatt.common.eventstore.ktor.configureEventStore +import com.github.connorwyatt.common.http.httpDependenciesModule +import com.github.connorwyatt.common.mongodb.configuration.MongoDBConfiguration +import com.github.connorwyatt.common.mongodb.kodein.mongoDBDependenciesModule +import com.github.connorwyatt.common.mongodb.ktor.configureMongoDB +import com.github.connorwyatt.common.rabbitmq.configuration.RabbitMQConfiguration +import com.github.connorwyatt.common.rabbitmq.kodein.rabbitMQDependenciesModule +import com.github.connorwyatt.common.rabbitmq.ktor.configureRabbitMQ +import com.github.connorwyatt.common.time.timeDependenciesModule import io.ktor.server.application.* import io.ktor.server.plugins.requestvalidation.* import io.ktor.server.plugins.statuspages.* diff --git a/server/src/main/kotlin/io/connorwyatt/common/server/ApplicationExt.kt b/server/src/main/kotlin/com/github/connorwyatt/common/server/ApplicationExt.kt similarity index 94% rename from server/src/main/kotlin/io/connorwyatt/common/server/ApplicationExt.kt rename to server/src/main/kotlin/com/github/connorwyatt/common/server/ApplicationExt.kt index a04d863..6dc8236 100644 --- a/server/src/main/kotlin/io/connorwyatt/common/server/ApplicationExt.kt +++ b/server/src/main/kotlin/com/github/connorwyatt/common/server/ApplicationExt.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.server +package com.github.connorwyatt.common.server -import io.connorwyatt.common.http.validation.ValidationProblemResponse +import com.github.connorwyatt.common.http.validation.ValidationProblemResponse import io.ktor.http.* import io.ktor.serialization.kotlinx.json.* import io.ktor.server.application.* diff --git a/server/src/main/kotlin/io/connorwyatt/common/server/Server.kt b/server/src/main/kotlin/com/github/connorwyatt/common/server/Server.kt similarity index 89% rename from server/src/main/kotlin/io/connorwyatt/common/server/Server.kt rename to server/src/main/kotlin/com/github/connorwyatt/common/server/Server.kt index 3c32b36..eb1c0a2 100644 --- a/server/src/main/kotlin/io/connorwyatt/common/server/Server.kt +++ b/server/src/main/kotlin/com/github/connorwyatt/common/server/Server.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.server +package com.github.connorwyatt.common.server import io.ktor.server.cio.* import io.ktor.server.engine.* diff --git a/time/src/main/kotlin/io/connorwyatt/common/time/TimeDependenciesModule.kt b/time/src/main/kotlin/com/github/connorwyatt/common/time/TimeDependenciesModule.kt similarity index 52% rename from time/src/main/kotlin/io/connorwyatt/common/time/TimeDependenciesModule.kt rename to time/src/main/kotlin/com/github/connorwyatt/common/time/TimeDependenciesModule.kt index f68eba9..02b8678 100644 --- a/time/src/main/kotlin/io/connorwyatt/common/time/TimeDependenciesModule.kt +++ b/time/src/main/kotlin/com/github/connorwyatt/common/time/TimeDependenciesModule.kt @@ -1,7 +1,7 @@ -package io.connorwyatt.common.time +package com.github.connorwyatt.common.time -import io.connorwyatt.common.time.clock.Clock -import io.connorwyatt.common.time.clock.RealClock +import com.github.connorwyatt.common.time.clock.Clock +import com.github.connorwyatt.common.time.clock.RealClock import org.kodein.di.DI import org.kodein.di.bindProvider import org.kodein.di.new diff --git a/time/src/main/kotlin/io/connorwyatt/common/time/TimeUtilities.kt b/time/src/main/kotlin/com/github/connorwyatt/common/time/TimeUtilities.kt similarity index 92% rename from time/src/main/kotlin/io/connorwyatt/common/time/TimeUtilities.kt rename to time/src/main/kotlin/com/github/connorwyatt/common/time/TimeUtilities.kt index c712061..588dfa3 100644 --- a/time/src/main/kotlin/io/connorwyatt/common/time/TimeUtilities.kt +++ b/time/src/main/kotlin/com/github/connorwyatt/common/time/TimeUtilities.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.time +package com.github.connorwyatt.common.time import java.time.Instant import java.time.ZoneId diff --git a/time/src/main/kotlin/io/connorwyatt/common/time/clock/Clock.kt b/time/src/main/kotlin/com/github/connorwyatt/common/time/clock/Clock.kt similarity index 58% rename from time/src/main/kotlin/io/connorwyatt/common/time/clock/Clock.kt rename to time/src/main/kotlin/com/github/connorwyatt/common/time/clock/Clock.kt index 7270a8a..e44e13f 100644 --- a/time/src/main/kotlin/io/connorwyatt/common/time/clock/Clock.kt +++ b/time/src/main/kotlin/com/github/connorwyatt/common/time/clock/Clock.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.time.clock +package com.github.connorwyatt.common.time.clock import java.time.Instant diff --git a/time/src/main/kotlin/io/connorwyatt/common/time/clock/RealClock.kt b/time/src/main/kotlin/com/github/connorwyatt/common/time/clock/RealClock.kt similarity index 67% rename from time/src/main/kotlin/io/connorwyatt/common/time/clock/RealClock.kt rename to time/src/main/kotlin/com/github/connorwyatt/common/time/clock/RealClock.kt index 46f49be..f32e4fa 100644 --- a/time/src/main/kotlin/io/connorwyatt/common/time/clock/RealClock.kt +++ b/time/src/main/kotlin/com/github/connorwyatt/common/time/clock/RealClock.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.time.clock +package com.github.connorwyatt.common.time.clock import java.time.Instant diff --git a/time/src/main/kotlin/io/connorwyatt/common/time/clock/testing/FakeClock.kt b/time/src/main/kotlin/com/github/connorwyatt/common/time/clock/testing/FakeClock.kt similarity index 73% rename from time/src/main/kotlin/io/connorwyatt/common/time/clock/testing/FakeClock.kt rename to time/src/main/kotlin/com/github/connorwyatt/common/time/clock/testing/FakeClock.kt index 9339bd4..984256a 100644 --- a/time/src/main/kotlin/io/connorwyatt/common/time/clock/testing/FakeClock.kt +++ b/time/src/main/kotlin/com/github/connorwyatt/common/time/clock/testing/FakeClock.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.time.clock.testing +package com.github.connorwyatt.common.time.clock.testing -import io.connorwyatt.common.time.clock.Clock +import com.github.connorwyatt.common.time.clock.Clock import java.time.Instant import java.time.temporal.TemporalAmount diff --git a/time/src/main/kotlin/io/connorwyatt/common/time/serialization/InstantSerializer.kt b/time/src/main/kotlin/com/github/connorwyatt/common/time/serialization/InstantSerializer.kt similarity index 91% rename from time/src/main/kotlin/io/connorwyatt/common/time/serialization/InstantSerializer.kt rename to time/src/main/kotlin/com/github/connorwyatt/common/time/serialization/InstantSerializer.kt index a6106c7..76e08f0 100644 --- a/time/src/main/kotlin/io/connorwyatt/common/time/serialization/InstantSerializer.kt +++ b/time/src/main/kotlin/com/github/connorwyatt/common/time/serialization/InstantSerializer.kt @@ -1,4 +1,4 @@ -package io.connorwyatt.common.time.serialization +package com.github.connorwyatt.common.time.serialization import java.time.Instant import kotlinx.serialization.* diff --git a/time/src/test/kotlin/io/connorwyatt/common/time/clock/testing/FakeClockTests.kt b/time/src/test/kotlin/com/github/connorwyatt/common/time/clock/testing/FakeClockTests.kt similarity index 86% rename from time/src/test/kotlin/io/connorwyatt/common/time/clock/testing/FakeClockTests.kt rename to time/src/test/kotlin/com/github/connorwyatt/common/time/clock/testing/FakeClockTests.kt index b373b86..734e6af 100644 --- a/time/src/test/kotlin/io/connorwyatt/common/time/clock/testing/FakeClockTests.kt +++ b/time/src/test/kotlin/com/github/connorwyatt/common/time/clock/testing/FakeClockTests.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.time.clock.testing +package com.github.connorwyatt.common.time.clock.testing -import io.connorwyatt.common.time.TimeUtilities +import com.github.connorwyatt.common.time.TimeUtilities import java.time.Duration import org.junit.jupiter.api.Test import strikt.api.expectThat diff --git a/validation/src/main/kotlin/io/connorwyatt/common/validation/ValidationError.kt b/validation/src/main/kotlin/com/github/connorwyatt/common/validation/ValidationError.kt similarity index 57% rename from validation/src/main/kotlin/io/connorwyatt/common/validation/ValidationError.kt rename to validation/src/main/kotlin/com/github/connorwyatt/common/validation/ValidationError.kt index 71bbe2a..d5dbba3 100644 --- a/validation/src/main/kotlin/io/connorwyatt/common/validation/ValidationError.kt +++ b/validation/src/main/kotlin/com/github/connorwyatt/common/validation/ValidationError.kt @@ -1,3 +1,3 @@ -package io.connorwyatt.common.validation +package com.github.connorwyatt.common.validation data class ValidationError(val path: String, val message: String) diff --git a/validation/src/main/kotlin/io/connorwyatt/common/validation/ValidatorMapper.kt b/validation/src/main/kotlin/com/github/connorwyatt/common/validation/ValidatorMapper.kt similarity index 55% rename from validation/src/main/kotlin/io/connorwyatt/common/validation/ValidatorMapper.kt rename to validation/src/main/kotlin/com/github/connorwyatt/common/validation/ValidatorMapper.kt index 38010d8..13a6b27 100644 --- a/validation/src/main/kotlin/io/connorwyatt/common/validation/ValidatorMapper.kt +++ b/validation/src/main/kotlin/com/github/connorwyatt/common/validation/ValidatorMapper.kt @@ -1,6 +1,6 @@ -package io.connorwyatt.common.validation +package com.github.connorwyatt.common.validation -import io.connorwyatt.common.result.Result +import com.github.connorwyatt.common.result.Result interface ValidatorMapper { fun validateAndMap(value: TInput): Result>