Skip to content

Commit

Permalink
Merge branch 'master' into update/fs2-core-3.10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
geirolz committed May 30, 2024
2 parents c69a77e + 41cfb5a commit a561992
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.8.0"
version = "3.8.1"
style = default
maxColumn = 120
align.preset = most
Expand Down
15 changes: 8 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Dependencies._
import microsites.ExtraMdFileConfig

ThisBuild / name := """fs2-rabbit"""
ThisBuild / name := "fs2-rabbit"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / crossScalaVersions := List("2.12.18", "2.13.12", "3.3.1")
ThisBuild / crossScalaVersions := List("2.12.18", "2.13.12", "3.3.3")
ThisBuild / versionScheme := Some("semver-spec")
ThisBuild / organization := "dev.profunktor"
ThisBuild / homepage := Some(url("https://fs2-rabbit.profunktor.dev/"))
Expand Down Expand Up @@ -56,7 +56,7 @@ val commonSettings = List(
libraryDependencies ++= commonDependencies(scalaVersion.value),
resolvers += "Apache public" at "https://repository.apache.org/content/groups/public/",
scalafmtOnCompile := true,
mimaPreviousArtifacts := Set(organization.value %% moduleName.value % "5.1.0")
mimaPreviousArtifacts := previousStableVersion.value.map(organization.value %% moduleName.value % _).toSet
)

def CoreDependencies(scalaVersionStr: String): List[ModuleID] =
Expand Down Expand Up @@ -92,10 +92,11 @@ def TestsDependencies(scalaVersionStr: String): List[ModuleID] =
)

lazy val noPublish = List(
publish := {},
publishLocal := {},
publishArtifact := false,
publish / skip := true
publish := {},
publishLocal := {},
publishArtifact := false,
publish / skip := true,
crossScalaVersions := Nil
)

lazy val `fs2-rabbit-root` = project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 ProfunKtor
* Copyright 2017-2024 ProfunKtor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 ProfunKtor
* Copyright 2017-2024 ProfunKtor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
*/

package dev.profunktor.fs2rabbit.effects
import cats.{Applicative, ApplicativeThrow}
import cats.{Applicative, ApplicativeError, ApplicativeThrow, MonadError}
import cats.data.Kleisli
import dev.profunktor.fs2rabbit.model.{AmqpFieldValue, AmqpProperties, ExchangeName, RoutingKey}
import dev.profunktor.fs2rabbit.model.AmqpFieldValue._
import cats.implicits._

object EnvelopeDecoder {
object EnvelopeDecoder extends EnvelopeDecoderInstances {

def apply[F[_], A](implicit e: EnvelopeDecoder[F, A]): EnvelopeDecoder[F, A] = e

def properties[F[_]: Applicative]: EnvelopeDecoder[F, AmqpProperties] =
Expand Down Expand Up @@ -81,3 +82,16 @@ object EnvelopeDecoder {
): EnvelopeDecoder[F, Option[A]] =
Kleisli(_.properties.headers.get(name).traverse(h => F.catchNonFatal(pf(h))))
}

sealed trait EnvelopeDecoderInstances {

implicit def decoderAttempt[F[_], E: ApplicativeError[F, *], A](implicit
decoder: EnvelopeDecoder[F, A]
): EnvelopeDecoder[F, Either[E, A]] =
decoder.attempt

implicit def decoderOption[F[_], E: ApplicativeError[F, *], A](implicit
decoder: EnvelopeDecoder[F, A]
): EnvelopeDecoder[F, Option[A]] =
decoder.attempt.map(_.toOption)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ import cats.effect.unsafe.implicits.global

class EnvelopeDecoderSpec extends AsyncFunSuite {

import EnvelopeDecoder._
// Available instances of EnvelopeDecoder for any ApplicativeError[F, Throwable]
EnvelopeDecoder[Either[Throwable, *], String]
EnvelopeDecoder[SyncIO, String]
EnvelopeDecoder[EitherT[IO, String, *], String]
EnvelopeDecoder[Try, String]
EnvelopeDecoder[Try, Option[String]]
EnvelopeDecoder[Try, Either[Throwable, String]]

test("should decode a UTF-8 string") {
val msg = "hello world!"
Expand Down Expand Up @@ -86,4 +89,32 @@ class EnvelopeDecoderSpec extends AsyncFunSuite {
.unsafeToFuture()
}

test("should decode a UTF-8 string - Attempt") {
val msg = "hello world!"
val raw = msg.getBytes(StandardCharsets.UTF_8)

EnvelopeDecoder[IO, Either[Throwable, String]]
.run(
AmqpEnvelope(DeliveryTag(0L), raw, AmqpProperties.empty, ExchangeName("test"), RoutingKey("test.route"), false)
)
.flatMap { result =>
IO(assert(result == Right(msg)))
}
.unsafeToFuture()
}

test("should decode a UTF-8 string - Attempt option") {
val msg = "hello world!"
val raw = msg.getBytes(StandardCharsets.UTF_8)

EnvelopeDecoder[IO, Option[String]]
.run(
AmqpEnvelope(DeliveryTag(0L), raw, AmqpProperties.empty, ExchangeName("test"), RoutingKey("test.route"), false)
)
.flatMap { result =>
IO(assert(result == Option(msg)))
}
.unsafeToFuture()
}

}
10 changes: 5 additions & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ object Dependencies {

object Version {
val cats = "2.10.0"
val catsEffect = "3.5.3"
val catsEffect = "3.5.4"
val fs2 = "3.10.2"
val circe = "0.14.6"
val circe = "0.14.7"
val amqpClient = "5.20.0"
val logback = "1.4.14"
val logback = "1.5.6"
val monix = "3.3.0"
val zio = "1.0.18"
val zioCats = "3.2.9.1"
val scodec = "1.2.0"
val dropwizard = "4.2.25"
val collectionCompat = "2.11.0"

val kindProjector = "0.13.2"
val kindProjector = "0.13.3"

val scalaTest = "3.2.18"
val scalaCheck = "1.17.0"
val scalaCheck = "1.17.1"
val scalaTestPlusScalaCheck = "3.2.14.0"
val disciplineScalaCheck = "2.2.0"
}
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ resolvers += "Typesafe Repository" at "https://repo.typesafe.com/typesafe/releas
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0")
addSbtPlugin("com.47deg" % "sbt-microsites" % "1.4.4")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.2")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.7")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.0")
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.1")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.3")

0 comments on commit a561992

Please sign in to comment.