Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change packages from io.connorwyatt to com.github.connorwyatt #7

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ allprojects {
localOnly = true
}

project.group = "io.connorwyatt.common"
project.group = "com.github.connorwyatt.common"
project.version = scmVersion.version
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.connorwyatt.common.data.models

interface Versioned {
val version: Long
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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<EventData>,
): 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(
Expand Down Expand Up @@ -70,14 +77,18 @@ class EventStoreClientWrapper(private val eventStoreDBClient: EventStoreDBClient
}

sealed interface ReadResult {
data class Success(val events: List<ResolvedEvent>, val streamPosition: Long) : ReadResult
data class Success(val events: List<ResolvedEvent>, 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
}
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.connorwyatt.common.eventstore.aggregates
package com.github.connorwyatt.common.eventstore.aggregates

import kotlin.reflect.KClass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.connorwyatt.common.eventstore.aggregates
package com.github.connorwyatt.common.eventstore.aggregates

import kotlin.reflect.KClass

Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.connorwyatt.common.eventstore.configuration
package com.github.connorwyatt.common.eventstore.configuration

data class EventStoreConfiguration(
val connectionString: String?,
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<EventHandlerDefinition>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
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
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<EventHandler>,
private val eventHandlerMap: EventHandlerMap,
private val resolvedEventMapper: ResolvedEventMapper
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.github.connorwyatt.common.eventstore.eventhandlers

annotation class SubscriptionName(val name: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.github.connorwyatt.common.eventstore.events

interface Event
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package io.connorwyatt.common.eventstore.events
package com.github.connorwyatt.common.eventstore.events

internal const val EVENT_CLASS_DISCRIMINATOR = "${'$'}${'$'}type"
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package io.connorwyatt.common.eventstore.events
package com.github.connorwyatt.common.eventstore.events

data class EventEnvelope<TEvent : Event>(val event: TEvent, val metadata: EventMetadata)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.connorwyatt.common.eventstore.events
package com.github.connorwyatt.common.eventstore.events

import kotlinx.serialization.*
import kotlinx.serialization.json.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.connorwyatt.common.eventstore.events
package com.github.connorwyatt.common.eventstore.events

import kotlin.reflect.KClass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.connorwyatt.common.eventstore.events
package com.github.connorwyatt.common.eventstore.events

import kotlin.reflect.KClass

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.connorwyatt.common.eventstore.events
package com.github.connorwyatt.common.eventstore.events

import kotlinx.serialization.*
import kotlinx.serialization.json.*
Expand Down
Original file line number Diff line number Diff line change
@@ -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<EventEnvelope<out Event>>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*

Expand Down
Loading