From 33a950457615c3daa2042490262dba2e2f9d31db Mon Sep 17 00:00:00 2001 From: Andrew Valencik Date: Sat, 29 May 2021 08:46:05 -0400 Subject: [PATCH] Upgrade to CE3, FS2 3, and http4s 0.23 --- build.sbt | 13 ++++--- .../cormorant/fs2/StreamingParserSpec.scala | 39 ++++++++----------- .../cormorant/http4s/package.scala | 16 ++++---- 3 files changed, 31 insertions(+), 37 deletions(-) diff --git a/build.sbt b/build.sbt index 43cedb04..2f15093f 100644 --- a/build.sbt +++ b/build.sbt @@ -79,10 +79,11 @@ lazy val cormorant = project.in(file(".")) val catsV = "2.1.1" -val catsEffectV = "2.1.4" -val catsEffectTestV = "0.4.2" +val catsEffectV = "3.1.1" +val catsEffectTestV = "1.1.0" +val fs2V = "3.0.4" val shapelessV = "2.3.3" -val http4sV = "0.21.18" +val http4sV = "0.23.0-RC1" val catsScalacheckV = "0.3.0" val munitV = "0.7.26" val munitCatsEffectV = "1.0.3" @@ -130,8 +131,8 @@ lazy val fs2 = project.in(file("modules/fs2")) .settings( name := "cormorant-fs2", libraryDependencies ++= Seq( - "co.fs2" %% "fs2-core" % "2.4.6", - "co.fs2" %% "fs2-io" % "2.4.6" % Test + "co.fs2" %% "fs2-core" % fs2V, + "co.fs2" %% "fs2-io" % fs2V % Test ) ) @@ -198,7 +199,7 @@ lazy val commonSettings = Seq( "org.typelevel" %% "cats-effect" % catsEffectV, "org.scalameta" %% "munit" % munitV % Test, "org.scalameta" %% "munit-scalacheck" % munitV % Test, - "org.typelevel" %% "munit-cats-effect-2" % munitCatsEffectV % Test, + "org.typelevel" %% "munit-cats-effect-3" % munitCatsEffectV % Test, "org.typelevel" %% "scalacheck-effect-munit" % scalacheckEffectV % Test, "io.chrisdavenport" %% "cats-scalacheck" % catsScalacheckV % Test, ) diff --git a/modules/fs2/src/test/scala/io/chrisdavenport/cormorant/fs2/StreamingParserSpec.scala b/modules/fs2/src/test/scala/io/chrisdavenport/cormorant/fs2/StreamingParserSpec.scala index bb060c62..07d1d9e9 100644 --- a/modules/fs2/src/test/scala/io/chrisdavenport/cormorant/fs2/StreamingParserSpec.scala +++ b/modules/fs2/src/test/scala/io/chrisdavenport/cormorant/fs2/StreamingParserSpec.scala @@ -4,7 +4,6 @@ package fs2 import cats.data.NonEmptyList import cats.effect._ import munit.CatsEffectSuite -import _root_.fs2.Stream import io.chrisdavenport.cormorant._ import java.io.ByteArrayInputStream import java.io.InputStream @@ -22,28 +21,22 @@ class StreamingParserSpec extends CatsEffectSuite { Larry,Bordowitz,larry@example.com Anonymous,Hippopotamus,hippo@example.com""" val source = IO.pure(new ByteArrayInputStream(ruinDelims(x).getBytes): InputStream) - Stream.resource(Blocker[IO]).flatMap{blocker => - _root_.fs2.io.readInputStream( - source, - chunkSize = 4, - blocker - ) + _root_.fs2.io.readInputStream( + source, + chunkSize = 4, + ) + .through(_root_.fs2.text.utf8Decode) + .through(parseComplete[IO]) + .compile + .toVector + .map{ v => + val header = CSV.Headers(NonEmptyList.of(CSV.Header("First Name"), CSV.Header("Last Name"), CSV.Header("Email"))) + val row1 = CSV.Row(NonEmptyList.of(CSV.Field("Larry"), CSV.Field("Bordowitz"), CSV.Field("larry@example.com"))) + val row2 = CSV.Row(NonEmptyList.of(CSV.Field("Anonymous"), CSV.Field("Hippopotamus"), CSV.Field("hippo@example.com"))) + assertEquals(Vector( + (header, row1), + (header, row2) + ), v) } - .through(_root_.fs2.text.utf8Decode) - .through(parseComplete[IO]) - .compile - .toVector - .map{ v => - val header = CSV.Headers(NonEmptyList.of(CSV.Header("First Name"), CSV.Header("Last Name"), CSV.Header("Email"))) - val row1 = CSV.Row(NonEmptyList.of(CSV.Field("Larry"), CSV.Field("Bordowitz"), CSV.Field("larry@example.com"))) - val row2 = CSV.Row(NonEmptyList.of(CSV.Field("Anonymous"), CSV.Field("Hippopotamus"), CSV.Field("hippo@example.com"))) - assertEquals(Vector( - (header, row1), - (header, row2) - ), v) - } } - - - } diff --git a/modules/http4s/src/main/scala/io/chrisdavenport/cormorant/http4s/package.scala b/modules/http4s/src/main/scala/io/chrisdavenport/cormorant/http4s/package.scala index 6a6ed1c9..91c2c815 100644 --- a/modules/http4s/src/main/scala/io/chrisdavenport/cormorant/http4s/package.scala +++ b/modules/http4s/src/main/scala/io/chrisdavenport/cormorant/http4s/package.scala @@ -14,8 +14,8 @@ package object http4s { printer: Printer = Printer.default, mediaType: MediaType = MediaType.text.csv ): EntityEncoder[F, CSV.Complete] = { - val contentTypeHeader: Header = headers.`Content-Type`(mediaType) - EntityEncoder.encodeBy(Headers.of(contentTypeHeader))( + val contentTypeHeader = headers.`Content-Type`(mediaType) + EntityEncoder.encodeBy(contentTypeHeader)( csvComplete => Entity(Stream(printer.print(csvComplete)).through(text.utf8Encode).covary[F]) ) } @@ -24,8 +24,8 @@ package object http4s { printer: Printer = Printer.default, mediaType: MediaType = MediaType.text.csv ): EntityEncoder[F, CSV.Rows] = { - val contentTypeHeader: Header = headers.`Content-Type`(mediaType) - EntityEncoder.encodeBy(Headers.of(contentTypeHeader))( + val contentTypeHeader = headers.`Content-Type`(mediaType) + EntityEncoder.encodeBy(contentTypeHeader)( csvRows => Entity(Stream(printer.print(csvRows)).through(text.utf8Encode).covary[F]) ) } @@ -35,8 +35,8 @@ package object http4s { p: Printer = Printer.default, mediaType: MediaType = MediaType.text.csv ): EntityEncoder[F, Stream[F, CSV.Row]] = { - val contentTypeHeader: Header = headers.`Content-Type`(mediaType) - EntityEncoder.encodeBy(Headers.of(contentTypeHeader))( + val contentTypeHeader = headers.`Content-Type`(mediaType) + EntityEncoder.encodeBy(contentTypeHeader)( s => Entity( s.through(encodeRows(p)) @@ -57,8 +57,8 @@ package object http4s { p: Printer = Printer.default, mediaType: MediaType = MediaType.text.csv ): EntityEncoder[F, Stream[F, A]] = { - val contentTypeHeader: Header = headers.`Content-Type`(mediaType) - EntityEncoder.encodeBy(Headers.of(contentTypeHeader))( + val contentTypeHeader = headers.`Content-Type`(mediaType) + EntityEncoder.encodeBy(contentTypeHeader)( s => Entity( s.through(writeLabelled(p))