diff --git a/build.sbt b/build.sbt index 7d5782f..cbc6d20 100644 --- a/build.sbt +++ b/build.sbt @@ -18,11 +18,11 @@ inThisBuild( "kitlangton", "Kit Langton", "kit.langton@gmail.com", - url("https://github.com/kitlangton"), - ), + url("https://github.com/kitlangton") + ) ), - sonatypeCredentialHost := "s01.oss.sonatype.org", - ), + sonatypeCredentialHost := "s01.oss.sonatype.org" + ) ) lazy val supportedScalaVersions = List(scala213) @@ -38,11 +38,11 @@ val postgresVersion = "42.3.6" val quillVersion = "4.1.0" val scalaJavaTimeVersion = "2.4.0" val sttpVersion = "3.7.1" -val zioHttpVersion = "2.0.0-RC10" +val zioHttpVersion = "2.0.0-RC11" val zioJsonVersion = "0.3.0-RC3" val zioNioVersion = "2.0.0" val zioProcessVersion = "0.7.1" -val zioVersion = "2.0.0" +val zioVersion = "2.0.3" val zioQueryVersion = "0.3.0" val sharedSettings = Seq( @@ -50,20 +50,20 @@ val sharedSettings = Seq( addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"), resolvers ++= Seq( "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots", - "Sonatype OSS Snapshots s01" at "https://s01.oss.sonatype.org/content/repositories/snapshots", + "Sonatype OSS Snapshots s01" at "https://s01.oss.sonatype.org/content/repositories/snapshots" ), libraryDependencies ++= Seq( "io.suzaku" %%% "boopickle" % boopickleVerison, "dev.zio" %%% "zio" % zioVersion, "dev.zio" %%% "zio-streams" % zioVersion, "dev.zio" %%% "zio-test" % zioVersion % Test, - "com.lihaoyi" %%% "fansi" % fansiVersion, + "com.lihaoyi" %%% "fansi" % fansiVersion ), scalacOptions ++= Seq("-Ymacro-annotations", "-Xfatal-warnings", "-deprecation"), scalaVersion := scala213, testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"), // semanticdbVersion := scalafixSemanticdb.revision, // only required for Scala 2.x, - scalacOptions += "-Yrangepos", + scalacOptions += "-Yrangepos" ) lazy val root = (project in file(".")) @@ -73,7 +73,7 @@ lazy val root = (project in file(".")) // crossScalaVersions must be set to Nil on the aggregating project crossScalaVersions := Nil, publish / skip := true, - welcomeMessage, + welcomeMessage ) lazy val cli = (project in file("cli")) @@ -108,21 +108,21 @@ lazy val cli = (project in file("cli")) "--initialize-at-run-time=io.netty.util.AbstractReferenceCounted", "--initialize-at-run-time=io.netty.channel.kqueue.KQueue", "--initialize-at-build-time=org.slf4j.LoggerFactory", - "-H:IncludeResources='.*'", + "-H:IncludeResources='.*'" ), libraryDependencies ++= Seq( "dev.zio" %% "zio-process" % zioProcessVersion, "dev.zio" %% "zio-nio" % zioNioVersion, "dev.zio" %% "zio-parser" % "0.1.7", "io.d11" %% "zhttp" % zioHttpVersion, - "org.jline" % "jline" % "3.21.0", + "org.jline" % "jline" % "3.21.0" ), resolvers ++= Seq( "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots", - "Sonatype OSS Snapshots s01" at "https://s01.oss.sonatype.org/content/repositories/snapshots", + "Sonatype OSS Snapshots s01" at "https://s01.oss.sonatype.org/content/repositories/snapshots" ), Compile / mainClass := Some("zio.app.Main"), - testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"), + testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework") ) .settings(sharedSettings) .dependsOn(cliShared, coreJVM) @@ -146,8 +146,8 @@ lazy val cliFrontend = project "io.github.cquiroz" %%% "scala-java-time-tzdb" % scalaJavaTimeVersion, "io.laminext" %%% "websocket" % laminextVersion, "com.softwaremill.sttp.client3" %%% "core" % sttpVersion, - "com.softwaremill.sttp.client3" %%% "monix" % sttpVersion, - ), + "com.softwaremill.sttp.client3" %%% "monix" % sttpVersion + ) ) .settings(sharedSettings) .dependsOn(cliShared, coreJS) @@ -163,7 +163,7 @@ lazy val cliShared = project }, scalaJSLinkerConfig ~= { _.withSourceMap(false) - }, + } ) lazy val core = crossProject(JSPlatform, JVMPlatform) @@ -179,7 +179,7 @@ lazy val core = crossProject(JSPlatform, JVMPlatform) testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"), resolvers ++= Seq( "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots", - "Sonatype OSS Snapshots s01" at "https://s01.oss.sonatype.org/content/repositories/snapshots", + "Sonatype OSS Snapshots s01" at "https://s01.oss.sonatype.org/content/repositories/snapshots" ), libraryDependencies ++= Seq( "org.scala-lang" % "scala-reflect" % scalaVersion.value, @@ -192,8 +192,8 @@ lazy val core = crossProject(JSPlatform, JVMPlatform) "com.softwaremill.sttp.client3" %%% "core" % sttpVersion, "io.getquill" %% "quill-jdbc-zio" % quillVersion, "org.postgresql" % "postgresql" % postgresVersion, - "org.scalameta" %% "scalameta" % "4.5.9", - ), + "org.scalameta" %% "scalameta" % "4.5.9" + ) ) lazy val coreJS = core.js @@ -208,14 +208,14 @@ lazy val examples = crossProject(JSPlatform, JVMPlatform) libraryDependencies ++= Seq( "dev.zio" %%% "zio" % zioVersion, "dev.zio" %% "zio-test" % zioVersion % Test, - "io.d11" %% "zhttp" % zioHttpVersion, - ), + "io.d11" %% "zhttp" % zioHttpVersion + ) ) .jvmSettings( libraryDependencies ++= Seq( "com.softwaremill.sttp.client3" %%% "core" % sttpVersion, - "com.softwaremill.sttp.client3" %% "async-http-client-backend-zio" % sttpVersion, - ), + "com.softwaremill.sttp.client3" %% "async-http-client-backend-zio" % sttpVersion + ) ) .jsSettings( scalaJSLinkerConfig ~= { @@ -228,8 +228,8 @@ lazy val examples = crossProject(JSPlatform, JVMPlatform) libraryDependencies ++= Seq( "com.raquo" %%% "laminar" % laminarVersion, "io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion, - "io.github.cquiroz" %%% "scala-java-time-tzdb" % scalaJavaTimeVersion, - ), + "io.github.cquiroz" %%% "scala-java-time-tzdb" % scalaJavaTimeVersion + ) ) .dependsOn(core) diff --git a/cli/src/main/scala/tui/TerminalApp.scala b/cli/src/main/scala/tui/TerminalApp.scala index af7fa15..82e69b5 100644 --- a/cli/src/main/scala/tui/TerminalApp.scala +++ b/cli/src/main/scala/tui/TerminalApp.scala @@ -37,9 +37,9 @@ sealed trait TerminalEvent[+I] trait TUI { def run[I, S, A]( - terminalApp: TerminalApp[I, S, A], - events: ZStream[Any, Throwable, I], - initialState: S + terminalApp: TerminalApp[I, S, A], + events: ZStream[Any, Throwable, I], + initialState: S ): Task[Option[A]] } @@ -52,7 +52,7 @@ object TUI { ZIO.serviceWithZIO[TUI](_.run(terminalApp, ZStream.never, initialState)) def runWithEvents[I, S, A]( - terminalApp: TerminalApp[I, S, A] + terminalApp: TerminalApp[I, S, A] )(events: ZStream[Any, Throwable, I], initialState: S): RIO[TUI, Option[A]] = ZIO.serviceWithZIO[TUI](_.run(terminalApp, events, initialState)) } @@ -61,9 +61,9 @@ case class TUILive(fullScreen: Boolean) extends TUI { var lastSize: Size = Size(0, 0) def run[I, S, A]( - terminalApp: TerminalApp[I, S, A], - events: ZStream[Any, Throwable, I], - initialState: S + terminalApp: TerminalApp[I, S, A], + events: ZStream[Any, Throwable, I], + initialState: S ): Task[Option[A]] = ZIO.scoped { Input @@ -75,35 +75,35 @@ case class TUILive(fullScreen: Boolean) extends TUI { oldMap: Ref[TextMap] <- Ref.make(TextMap.ofDim(0, 0)) _ <- (for { - _ <- ZIO.succeed(Input.ec.clear()) - (width, height) <- ZIO.succeed(Input.terminalSize) - _ <- renderFullScreen(oldMap, terminalApp, initialState, width, height) - } yield ()).when(fullScreen) + _ <- ZIO.succeed(Input.ec.clear()) + (width, height) <- ZIO.succeed(Input.terminalSize) + _ <- renderFullScreen(oldMap, terminalApp, initialState, width, height) + } yield ()).when(fullScreen) renderStream = stateRef.changes - .zipWithLatest(Input.terminalSizeStream)((_, _)) + .zipLatestWith(Input.terminalSizeStream)((_, _)) .tap { case (state, (width, height)) => if (fullScreen) renderFullScreen(oldMap, terminalApp, state, width, height) else renderTerminal(terminalApp, state) } updateStream = Input.keyEventStream.mergeEither(events).tap { keyEvent => - val event = keyEvent match { - case Left(value) => TerminalEvent.SystemEvent(value) - case Right(value) => TerminalEvent.UserEvent(value) - } - - stateRef.updateZIO { state => - terminalApp.update(state, event) match { - case Step.Update(state) => ZIO.succeed(state) - case Step.Done(result) => resultPromise.succeed(Some(result)).as(state) - case Step.Exit => resultPromise.succeed(None).as(state) - } - } - } - - _ <- ZStream.mergeAllUnbounded()(renderStream, updateStream).interruptWhen(resultPromise.await).runDrain + val event = keyEvent match { + case Left(value) => TerminalEvent.SystemEvent(value) + case Right(value) => TerminalEvent.UserEvent(value) + } + + stateRef.updateZIO { state => + terminalApp.update(state, event) match { + case Step.Update(state) => ZIO.succeed(state) + case Step.Done(result) => resultPromise.succeed(Some(result)).as(state) + case Step.Exit => resultPromise.succeed(None).as(state) + } + } + } + + _ <- ZStream.mergeAllUnbounded()(renderStream, updateStream).interruptWhen(resultPromise.await).runDrain result <- resultPromise.await } yield result } @@ -113,11 +113,11 @@ case class TUILive(fullScreen: Boolean) extends TUI { var lastWidth = 0 def renderFullScreen[I, S, A]( - oldMap: Ref[TextMap], - terminalApp: TerminalApp[I, S, A], - state: S, - width: Int, - height: Int + oldMap: Ref[TextMap], + terminalApp: TerminalApp[I, S, A], + state: S, + width: Int, + height: Int ): UIO[Unit] = oldMap.update { oldMap => if (lastWidth != width || lastHeight != height) { diff --git a/cli/src/main/scala/zio/app/DevMode.scala b/cli/src/main/scala/zio/app/DevMode.scala index 8e3fc19..6790e8e 100644 --- a/cli/src/main/scala/zio/app/DevMode.scala +++ b/cli/src/main/scala/zio/app/DevMode.scala @@ -21,19 +21,19 @@ object DevMode { .unwrap( for { process <- Command("sbt", command, "--color=always").run - .tap(_.exitCode.fork) + .tap(_.exitCode.fork) errorStream = ZStream - .fromZIO(process.stderr.lines.flatMap { lines => - val errorString = lines.mkString - if (errorString.contains("waiting for lock")) - ZIO.fail(SbtError.WaitingForLock) - else if (errorString.contains("Invalid commands")) - ZIO.fail(SbtError.InvalidCommand(s"sbt $command")) - else { - println(s"ERRRRRRR ${errorString}") - ZIO.fail(SbtError.SbtErrorMessage(errorString)) - } - }) + .fromZIO(process.stderr.lines.flatMap { lines => + val errorString = lines.mkString + if (errorString.contains("waiting for lock")) + ZIO.fail(SbtError.WaitingForLock) + else if (errorString.contains("Invalid commands")) + ZIO.fail(SbtError.InvalidCommand(s"sbt $command")) + else { + println(s"ERRRRRRR ${errorString}") + ZIO.fail(SbtError.SbtErrorMessage(errorString)) + } + }) } yield ZStream.mergeAllUnbounded()( ZStream.succeed(s"sbt $command"), process.stdout.linesStream, diff --git a/core/shared/src/main/scala/zio/app/internal/BackendUtils.scala b/core/shared/src/main/scala/zio/app/internal/BackendUtils.scala index e1dbf9b..395b16b 100644 --- a/core/shared/src/main/scala/zio/app/internal/BackendUtils.scala +++ b/core/shared/src/main/scala/zio/app/internal/BackendUtils.scala @@ -22,13 +22,13 @@ object BackendUtils { def makeRoute[R, E: Pickler, A: Pickler, B: Pickler]( service: String, method: String, - call: A => ZIO[R, E, B], + call: A => ZIO[R, E, B] ): HttpApp[R, Throwable] = { val service0 = urlEncode(service) val method0 = method Http.collectZIO { case post @ Method.POST -> !! / `service0` / `method0` => - post.body.orDie.flatMap { body => - val byteBuffer = ByteBuffer.wrap(body.toArray) + post.body.asArray.orDie.flatMap { body => + val byteBuffer = ByteBuffer.wrap(body) val unpickled = Unpickle[A].fromBytes(byteBuffer) call(unpickled) .map(pickle[B](_)) @@ -45,7 +45,7 @@ object BackendUtils { def makeRouteNullary[R, E: Pickler, A: Pickler]( service: String, method: String, - call: ZIO[R, E, A], + call: ZIO[R, E, A] ): HttpApp[R, Throwable] = { val service0 = urlEncode(service) val method0 = method @@ -64,13 +64,13 @@ object BackendUtils { def makeRouteStream[R, E: Pickler, A: Pickler, B: Pickler]( service: String, method: String, - call: A => ZStream[R, E, B], + call: A => ZStream[R, E, B] ): HttpApp[R, Nothing] = { val service0 = service val method0 = method Http.collectZIO { case post @ Method.POST -> !! / `service0` / `method0` => - post.body.orDie.flatMap { body => - val byteBuffer = ByteBuffer.wrap(body.toArray) + post.body.asArray.orDie.flatMap { body => + val byteBuffer = ByteBuffer.wrap(body) val unpickled = Unpickle[A].fromBytes(byteBuffer) ZIO.environment[R].map { env => makeStreamResponse(call(unpickled), env) @@ -82,7 +82,7 @@ object BackendUtils { def makeRouteNullaryStream[R, E: Pickler, A: Pickler]( service: String, method: String, - call: ZStream[R, E, A], + call: ZStream[R, E, A] ): HttpApp[R, Nothing] = { val service0 = service val method0 = method @@ -96,14 +96,14 @@ object BackendUtils { private def pickle[A: Pickler](value: A): Response = { val bytes: ByteBuffer = Pickle.intoBytes(value) val byteBuf = Unpooled.wrappedBuffer(bytes) - val httpData = HttpData.fromByteBuf(byteBuf) + val body = Body.fromByteBuf(byteBuf) - Response(status = Status.Ok, headers = Headers(bytesContent), data = httpData) + Response(status = Status.Ok, headers = Headers(bytesContent), body = body) } private def makeStreamResponse[A: Pickler, E: Pickler, R]( stream: ZStream[R, E, A], - env: ZEnvironment[R], + env: ZEnvironment[R] ): Response = { val responseStream: ZStream[Any, Throwable, Byte] = stream.mapConcatChunk { a => @@ -115,7 +115,7 @@ object BackendUtils { } .provideEnvironment(env) - Response(data = HttpData.fromStream(responseStream)) + Response(body = Body.fromStream(responseStream)) } } @@ -132,7 +132,7 @@ object CustomPicklers { // local date time implicit val localDateTimePickler: Pickler[java.time.LocalDateTime] = transformPickler((t: Long) => - java.time.LocalDateTime.ofInstant(Instant.ofEpochMilli(t), java.time.ZoneId.of("UTC")), + java.time.LocalDateTime.ofInstant(Instant.ofEpochMilli(t), java.time.ZoneId.of("UTC")) )(_.toInstant(java.time.ZoneOffset.UTC).toEpochMilli) } diff --git a/examples/jvm/src/main/scala/examples/Backend.scala b/examples/jvm/src/main/scala/examples/Backend.scala index 81ae77e..e71a54d 100644 --- a/examples/jvm/src/main/scala/examples/Backend.scala +++ b/examples/jvm/src/main/scala/examples/Backend.scala @@ -20,6 +20,6 @@ object Backend extends ZIOAppDefault { } yield ()) .provide( ExampleServiceLive.layer, - ParameterizedServiceLive.layer + ParameterizedServiceLive.layer, ) }