-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify transport and provider response; remove peek; remove ObjectM…
…apper creation from Jackson codec, ask for it implicitly
- Loading branch information
Showing
61 changed files
with
674 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package poppet | ||
|
||
import poppet.core.Request | ||
import poppet.core.Response | ||
|
||
trait CoreDsl { | ||
type Codec[A, B] = core.Codec[A, B] | ||
type CodecK[F[_], G[_]] = core.CodecK[F, G] | ||
type Failure = core.Failure | ||
type CodecFailure[I] = core.CodecFailure[I] | ||
type FailureHandler[F[_]] = core.FailureHandler[F] | ||
type Peek[F[_], I] = (Request[I] => F[Response[I]]) => (Request[I] => F[Response[I]]) | ||
type Request[I] = core.Request[I] | ||
type Response[I] = core.Response[I] | ||
|
||
val FailureHandler = core.FailureHandler | ||
val Request = core.Request | ||
val Response = core.Response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,41 @@ | ||
package poppet.consumer.core | ||
|
||
import cats.Monad | ||
import cats.implicits._ | ||
import cats.Monad | ||
import poppet.consumer.all._ | ||
import poppet.core.Request | ||
import poppet.core.Response | ||
|
||
/** | ||
* @param transport function that transfers data to the provider | ||
* @param peek function that can decorate given request -> response function without changing the types. | ||
* It is mostly used to peek on parsed dtos, for example for logging. | ||
* | ||
* @tparam F consumer data kind, for example Future[_] | ||
* @tparam I intermediate data type, for example Json | ||
* @tparam S service type, for example HelloService | ||
*/ | ||
class Consumer[F[_] : Monad, I, S]( | ||
class Consumer[F[_]: Monad, I, S]( | ||
transport: Transport[F, I], | ||
peek: Peek[F, I], | ||
fh: FailureHandler[F], | ||
processor: ConsumerProcessor[F, I, S])( | ||
implicit qcodec: Codec[Request[I], I], | ||
scodec: Codec[I, Response[I]], | ||
processor: ConsumerProcessor[F, I, S] | ||
) { | ||
def service: S = processor( | ||
peek(input => for { | ||
request <- qcodec(input).fold(fh.apply, Monad[F].pure) | ||
response <- transport(request) | ||
output <- scodec(response).fold(fh.apply, Monad[F].pure) | ||
} yield output), | ||
fh, | ||
) | ||
def service: S = processor(transport, fh) | ||
} | ||
|
||
object Consumer { | ||
|
||
def apply[F[_], I]( | ||
client: Transport[F, I], | ||
peek: Peek[F, I] = identity[Request[I] => F[Response[I]]](_), | ||
fh: FailureHandler[F] = FailureHandler.throwing[F])( | ||
implicit FM: Monad[F], | ||
qcodec: Codec[Request[I], I], | ||
scodec: Codec[I, Response[I]] | ||
): Builder[F, I] = new Builder[F, I](client, peek, fh) | ||
fh: FailureHandler[F] = FailureHandler.throwing[F] | ||
)(implicit | ||
F: Monad[F], | ||
): Builder[F, I] = new Builder[F, I](client, fh) | ||
|
||
class Builder[F[_], I]( | ||
client: Transport[F, I], | ||
peek: Peek[F, I], | ||
fh: FailureHandler[F])( | ||
implicit FM: Monad[F], | ||
qcodec: Codec[Request[I], I], | ||
scodec: Codec[I, Response[I]] | ||
fh: FailureHandler[F] | ||
)(implicit | ||
F: Monad[F], | ||
) { | ||
def service[S](implicit processor: ConsumerProcessor[F, I, S]): S = | ||
new Consumer(client, peek, fh, processor).service | ||
new Consumer(client, fh, processor).service | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.