Skip to content

Commit

Permalink
Merge pull request #201 from fraktalio/feature/flow-preview-to-experi…
Browse files Browse the repository at this point in the history
…mental-and-stable

Promote ``@FlowPreview` API to stable/experimental
  • Loading branch information
idugalic authored May 14, 2023
2 parents 9ce2782 + c1ec331 commit 264fbb6
Show file tree
Hide file tree
Showing 30 changed files with 7 additions and 125 deletions.
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
name: Bug report about: Create a report to help us improve title: ''
name:
Bug report about:
Create a report to help us improve title: ''
labels: ''
assignees: ''

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import arrow.core.Either
import arrow.core.raise.either
import com.fraktalio.fmodel.application.Error.CommandHandlingFailed
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.*

/**
Expand All @@ -31,7 +30,6 @@ import kotlinx.coroutines.flow.*
*
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@FlowPreview
fun <C, S, E> EventSourcingAggregate<C, S, E>.handleWithEffect(command: C): Flow<Either<Error, E>> =
command
.fetchEvents()
Expand All @@ -49,7 +47,6 @@ fun <C, S, E> EventSourcingAggregate<C, S, E>.handleWithEffect(command: C): Flow
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@ExperimentalCoroutinesApi
@FlowPreview
fun <C, S, E> EventSourcingOrchestratingAggregate<C, S, E>.handleWithEffect(command: C): Flow<Either<Error, E>> =
command
.fetchEvents()
Expand All @@ -66,7 +63,6 @@ fun <C, S, E> EventSourcingOrchestratingAggregate<C, S, E>.handleWithEffect(comm
*
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@FlowPreview
fun <C, S, E, V> EventSourcingLockingAggregate<C, S, E, V>.handleOptimisticallyWithEffect(command: C): Flow<Either<Error, Pair<E, V>>> =
flow {
val events = command.fetchEvents()
Expand All @@ -88,7 +84,6 @@ fun <C, S, E, V> EventSourcingLockingAggregate<C, S, E, V>.handleOptimisticallyW
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@ExperimentalCoroutinesApi
@FlowPreview
fun <C, S, E, V> EventSourcingLockingOrchestratingAggregate<C, S, E, V>.handleOptimisticallyWithEffect(command: C): Flow<Either<Error, Pair<E, V>>> =
command
.fetchEvents().map { it.first }
Expand All @@ -99,67 +94,55 @@ fun <C, S, E, V> EventSourcingLockingOrchestratingAggregate<C, S, E, V>.handleOp


@ExperimentalCoroutinesApi
@FlowPreview
fun <C, S, E> EventSourcingAggregate<C, S, E>.handleWithEffect(commands: Flow<C>): Flow<Either<Error, E>> =
commands
.flatMapConcat { handleWithEffect(it) }
.catch { emit(either { raise(CommandHandlingFailed(it)) }) }

@ExperimentalCoroutinesApi
@FlowPreview
fun <C, S, E> EventSourcingOrchestratingAggregate<C, S, E>.handleWithEffect(commands: Flow<C>): Flow<Either<Error, E>> =
commands
.flatMapConcat { handleWithEffect(it) }
.catch { emit(either { raise(CommandHandlingFailed(it)) }) }

@ExperimentalCoroutinesApi
@FlowPreview
fun <C, S, E, V> EventSourcingLockingAggregate<C, S, E, V>.handleOptimisticallyWithEffect(commands: Flow<C>): Flow<Either<Error, Pair<E, V>>> =
commands
.flatMapConcat { handleOptimisticallyWithEffect(it) }
.catch { emit(either { raise(CommandHandlingFailed(it)) }) }

@ExperimentalCoroutinesApi
@FlowPreview
fun <C, S, E, V> EventSourcingLockingOrchestratingAggregate<C, S, E, V>.handleOptimisticallyWithEffect(commands: Flow<C>): Flow<Either<Error, Pair<E, V>>> =
commands
.flatMapConcat { handleOptimisticallyWithEffect(it) }
.catch { emit(either { raise(CommandHandlingFailed(it)) }) }

@FlowPreview
fun <C, E> C.publishWithEffect(aggregate: EventSourcingAggregate<C, *, E>): Flow<Either<Error, E>> =
aggregate.handleWithEffect(this)

@ExperimentalCoroutinesApi
@FlowPreview
fun <C, E> C.publishWithEffect(aggregate: EventSourcingOrchestratingAggregate<C, *, E>): Flow<Either<Error, E>> =
aggregate.handleWithEffect(this)

@FlowPreview
fun <C, E, V> C.publishOptimisticallyWithEffect(aggregate: EventSourcingLockingAggregate<C, *, E, V>): Flow<Either<Error, Pair<E, V>>> =
aggregate.handleOptimisticallyWithEffect(this)

@ExperimentalCoroutinesApi
@FlowPreview
fun <C, E, V> C.publishOptimisticallyWithEffect(aggregate: EventSourcingLockingOrchestratingAggregate<C, *, E, V>): Flow<Either<Error, Pair<E, V>>> =
aggregate.handleOptimisticallyWithEffect(this)

@ExperimentalCoroutinesApi
@FlowPreview
fun <C, E> Flow<C>.publishWithEffect(aggregate: EventSourcingAggregate<C, *, E>): Flow<Either<Error, E>> =
aggregate.handleWithEffect(this)

@ExperimentalCoroutinesApi
@FlowPreview
fun <C, E> Flow<C>.publishWithEffect(aggregate: EventSourcingOrchestratingAggregate<C, *, E>): Flow<Either<Error, E>> =
aggregate.handleWithEffect(this)

@ExperimentalCoroutinesApi
@FlowPreview
fun <C, E, V> Flow<C>.publishOptimisticallyWithEffect(aggregate: EventSourcingLockingAggregate<C, *, E, V>): Flow<Either<Error, Pair<E, V>>> =
aggregate.handleOptimisticallyWithEffect(this)

@ExperimentalCoroutinesApi
@FlowPreview
fun <C, E, V> Flow<C>.publishOptimisticallyWithEffect(aggregate: EventSourcingLockingOrchestratingAggregate<C, *, E, V>): Flow<Either<Error, Pair<E, V>>> =
aggregate.handleOptimisticallyWithEffect(this)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import arrow.core.raise.either
import com.fraktalio.fmodel.application.Error.ActionResultHandlingFailed
import com.fraktalio.fmodel.application.Error.ActionResultPublishingFailed
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flatMapConcat
Expand Down Expand Up @@ -51,7 +50,6 @@ fun <AR, A> SagaManager<AR, A>.handleWithEffect(actionResult: AR): Flow<Either<E
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@ExperimentalCoroutinesApi
@FlowPreview
fun <AR, A> SagaManager<AR, A>.handleWithEffect(actionResults: Flow<AR>): Flow<Either<Error, A>> =
actionResults
.flatMapConcat { handleWithEffect(it) }
Expand All @@ -78,7 +76,6 @@ fun <AR, A> AR.publishWithEffect(sagaManager: SagaManager<AR, A>): Flow<Either<E
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@ExperimentalCoroutinesApi
@FlowPreview
fun <AR, A> Flow<AR>.publishWithEffect(sagaManager: SagaManager<AR, A>): Flow<Either<Error, A>> =
sagaManager.handleWithEffect(this)

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import arrow.core.Either
import arrow.core.raise.catch
import arrow.core.raise.either
import com.fraktalio.fmodel.application.Error.*
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map
Expand All @@ -33,7 +32,6 @@ import kotlinx.coroutines.flow.map
*
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@FlowPreview
suspend fun <C, S, E, I> I.handleWithEffect(command: C): Either<Error, S> where I : StateComputation<C, S, E>,
I : StateRepository<C, S> {
/**
Expand Down Expand Up @@ -97,7 +95,6 @@ suspend fun <C, S, E, I> I.handleWithEffect(command: C): Either<Error, S> where
*
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@FlowPreview
suspend fun <C, S, E, V, I> I.handleOptimisticallyWithEffect(command: C): Either<Error, Pair<S, V>> where I : StateComputation<C, S, E>,
I : StateLockingRepository<C, S, V> {
/**
Expand Down Expand Up @@ -162,7 +159,6 @@ suspend fun <C, S, E, V, I> I.handleOptimisticallyWithEffect(command: C): Either
*
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@FlowPreview
fun <C, S, E, I> I.handleWithEffect(commands: Flow<C>): Flow<Either<Error, S>> where I : StateComputation<C, S, E>,
I : StateRepository<C, S> =
commands
Expand All @@ -177,7 +173,6 @@ fun <C, S, E, I> I.handleWithEffect(commands: Flow<C>): Flow<Either<Error, S>> w
*
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@FlowPreview
fun <C, S, E, V, I> I.handleOptimisticallyWithEffect(commands: Flow<C>): Flow<Either<Error, Pair<S, V>>> where I : StateComputation<C, S, E>,
I : StateLockingRepository<C, S, V> =
commands
Expand All @@ -192,7 +187,6 @@ fun <C, S, E, V, I> I.handleOptimisticallyWithEffect(commands: Flow<C>): Flow<Ei
*
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@FlowPreview
suspend fun <C, S, E, A> C.publishWithEffect(aggregate: A): Either<Error, S> where A : StateComputation<C, S, E>,
A : StateRepository<C, S> =
aggregate.handleWithEffect(this)
Expand All @@ -205,7 +199,6 @@ suspend fun <C, S, E, A> C.publishWithEffect(aggregate: A): Either<Error, S> whe
*
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@FlowPreview
suspend fun <C, S, E, V, A> C.publishOptimisticallyWithEffect(aggregate: A): Either<Error, Pair<S, V>> where A : StateComputation<C, S, E>,
A : StateLockingRepository<C, S, V> =
aggregate.handleOptimisticallyWithEffect(this)
Expand All @@ -218,7 +211,6 @@ suspend fun <C, S, E, V, A> C.publishOptimisticallyWithEffect(aggregate: A): Eit
*
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@FlowPreview
fun <C, S, E, A> Flow<C>.publishWithEffect(aggregate: A): Flow<Either<Error, S>> where A : StateComputation<C, S, E>,
A : StateRepository<C, S> =
aggregate.handleWithEffect(this)
Expand All @@ -231,7 +223,6 @@ fun <C, S, E, A> Flow<C>.publishWithEffect(aggregate: A): Flow<Either<Error, S>>
*
* @author Иван Дугалић / Ivan Dugalic / @idugalic
*/
@FlowPreview
fun <C, S, E, V, A> Flow<C>.publishOptimisticallyWithEffect(aggregate: A): Flow<Either<Error, Pair<S, V>>> where A : StateComputation<C, S, E>,
A : StateLockingRepository<C, S, V> =
aggregate.handleOptimisticallyWithEffect(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ import com.fraktalio.fmodel.domain.examples.numbers.odd.command.oddNumberDecider
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldContainExactly
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.toList

/**
* DSL - Given
*/
@FlowPreview
private fun <C, S, E> IDecider<C, S, E>.given(
repository: EventRepository<C, E>,
command: () -> C
Expand All @@ -37,7 +35,6 @@ private fun <C, S, E> IDecider<C, S, E>.given(
eventRepository = repository
).handleWithEffect(command())

@FlowPreview
private fun <C, S, E, V> IDecider<C, S, E>.given(
repository: EventLockingRepository<C, E, V>,
command: () -> C
Expand Down Expand Up @@ -66,7 +63,6 @@ private suspend infix fun <E, V> Flow<Either<Error, Pair<E, V>>>.thenEventPairs(
* Event sourced aggregate test
*/
@OptIn(ExperimentalCoroutinesApi::class)
@FlowPreview
class EventSourcedAggregateTest : FunSpec({
val evenDecider = evenNumberDecider()
val oddDecider = oddNumberDecider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.shouldBeInstanceOf
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview

/**
* DSL - Given
*/
@FlowPreview
private suspend fun <C, S, E> IDecider<C, S, E>.given(
repository: StateRepository<C, S>,
command: () -> C
Expand All @@ -35,7 +33,6 @@ private suspend fun <C, S, E> IDecider<C, S, E>.given(
stateRepository = repository
).handleWithEffect(command())

@FlowPreview
private suspend fun <C, S, E, V> IDecider<C, S, E>.given(
repository: StateLockingRepository<C, S, V>,
command: () -> C
Expand Down Expand Up @@ -83,7 +80,6 @@ private fun <S> Either<Error, S>.thenError() {
* State-stored aggregate test
*/
@OptIn(ExperimentalCoroutinesApi::class)
@FlowPreview
class StateStoredAggregateTest : FunSpec({
val evenDecider = evenNumberDecider()
val oddDecider = oddNumberDecider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.fraktalio.fmodel.domain.examples.numbers.api.NumberEvent
import com.fraktalio.fmodel.domain.examples.numbers.api.NumberEvent.OddNumberEvent
import com.fraktalio.fmodel.domain.examples.numbers.api.OddNumberState
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview


/**
Expand All @@ -42,7 +41,7 @@ import kotlinx.coroutines.FlowPreview
* @param repository the event-sourcing repository for all (even and odd) numbers
* @return the event-sourcing aggregate instance for all (even and odd) numbers
*/
@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class)
@OptIn(ExperimentalCoroutinesApi::class)
fun numberAggregate(
evenNumberDecider: Decider<EvenNumberCommand?, EvenNumberState, NumberEvent.EvenNumberEvent?>,
oddNumberDecider: Decider<OddNumberCommand?, OddNumberState, OddNumberEvent?>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.fraktalio.fmodel.domain.examples.numbers.api.NumberEvent
import com.fraktalio.fmodel.domain.examples.numbers.api.NumberEvent.OddNumberEvent
import com.fraktalio.fmodel.domain.examples.numbers.api.OddNumberState
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview


/**
Expand All @@ -42,7 +41,7 @@ import kotlinx.coroutines.FlowPreview
* @param repository the state-stored repository for all (even and odd) numbers
* @return the state-stored aggregate instance for all (even and odd) numbers
*/
@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class)
@OptIn(ExperimentalCoroutinesApi::class)
fun numberStateStoredAggregate(
evenNumberDecider: Decider<EvenNumberCommand?, EvenNumberState, NumberEvent.EvenNumberEvent?>,
oddNumberDecider: Decider<OddNumberCommand?, OddNumberState, OddNumberEvent?>,
Expand Down
Loading

0 comments on commit 264fbb6

Please sign in to comment.