diff --git a/build.sbt b/build.sbt index 48f4e59..74330b2 100644 --- a/build.sbt +++ b/build.sbt @@ -17,15 +17,15 @@ IWDeps.tapirCore, IWDeps.tapirZIOJson, IWDeps.useZIOJson, - IWDeps.tapirSttpClient + IWDeps.tapirSttpClient, + IWDeps.sttpClientLib("zio") ) .jvmSettings( IWDeps.tapirZIO, IWDeps.tapirZIOHttp4sServer, IWDeps.useZIOJson, - IWDeps.sttpClientLib("async-http-client-backend-zio"), - IWDeps.zioLib("interop-reactivestreams", "2.0.0"), - IWDeps.zioLib("nio", "2.0.0"), + IWDeps.zioInteropReactiveStreams, + IWDeps.zioNIO, excludeDependencies += // Gets transitively dragged in by zio-nio, conflicting with _3 ExclusionRule("org.scala-lang.modules", "scala-collection-compat_2.13") ) @@ -106,9 +106,12 @@ .dependsOn(`ui-model`.js) lazy val root = (project in file(".")) - .settings(name := "iw-support", publish / skip := true) - // Auto activates for all projects, but make sure we have required dependencies .enablePlugins(IWScalaProjectPlugin, GitVersioning) + .settings( + name := "iw-support", + publish / skip := true, + git.useGitDescribe := true + ) .aggregate( core.js, core.jvm, diff --git a/build.sbt b/build.sbt index 48f4e59..74330b2 100644 --- a/build.sbt +++ b/build.sbt @@ -17,15 +17,15 @@ IWDeps.tapirCore, IWDeps.tapirZIOJson, IWDeps.useZIOJson, - IWDeps.tapirSttpClient + IWDeps.tapirSttpClient, + IWDeps.sttpClientLib("zio") ) .jvmSettings( IWDeps.tapirZIO, IWDeps.tapirZIOHttp4sServer, IWDeps.useZIOJson, - IWDeps.sttpClientLib("async-http-client-backend-zio"), - IWDeps.zioLib("interop-reactivestreams", "2.0.0"), - IWDeps.zioLib("nio", "2.0.0"), + IWDeps.zioInteropReactiveStreams, + IWDeps.zioNIO, excludeDependencies += // Gets transitively dragged in by zio-nio, conflicting with _3 ExclusionRule("org.scala-lang.modules", "scala-collection-compat_2.13") ) @@ -106,9 +106,12 @@ .dependsOn(`ui-model`.js) lazy val root = (project in file(".")) - .settings(name := "iw-support", publish / skip := true) - // Auto activates for all projects, but make sure we have required dependencies .enablePlugins(IWScalaProjectPlugin, GitVersioning) + .settings( + name := "iw-support", + publish / skip := true, + git.useGitDescribe := true + ) .aggregate( core.js, core.jvm, diff --git a/tapir/js/src/main/scala/works/iterative/tapir/CustomTapirPlatformSpecific.scala b/tapir/js/src/main/scala/works/iterative/tapir/CustomTapirPlatformSpecific.scala index 61e0586..5484143 100644 --- a/tapir/js/src/main/scala/works/iterative/tapir/CustomTapirPlatformSpecific.scala +++ b/tapir/js/src/main/scala/works/iterative/tapir/CustomTapirPlatformSpecific.scala @@ -8,17 +8,17 @@ import sttp.client3.SttpBackend import sttp.capabilities.WebSockets import scala.concurrent.ExecutionContext -import sttp.client3.FetchBackend import sttp.client3.FetchOptions import org.scalajs.dom +import sttp.client3.impl.zio.FetchZioBackend trait CustomTapirPlatformSpecific extends SttpClientInterpreter: self: CustomTapir => - type Backend = SttpBackend[Future, WebSockets] + type Backend = SttpBackend[Task, WebSockets] val clientLayer: ULayer[Backend] = ZLayer.succeed( - FetchBackend( + FetchZioBackend( FetchOptions( Some(dom.RequestCredentials.`same-origin`), Some(dom.RequestMode.`same-origin`) @@ -34,17 +34,9 @@ wsToPipe: WebSocketToPipe[Any] ): I => Task[O] = val req = toRequestThrowErrors(endpoint, baseUri.toUri) - (i: I) => - ZIO.fromFuture { implicit ec => - val resp = backend.responseMonad.map( - backend.send(req(i).followRedirects(false)) - )(_.body) - resp.onComplete { - case scala.util.Failure(e: RuntimeException) - if e.getMessage == "Unexpected redirect" => - // Reload window on redirect, as it means that we need to log in again - org.scalajs.dom.window.location.reload(true) - case _ => () - } - resp - } + req(_).followRedirects(false).send(backend).map(_.body).tapError { + case e: RuntimeException if e.getMessage == "Unexpected redirect" => + // Reload window on redirect, as it means that we need to log in again + ZIO.attempt(org.scalajs.dom.window.location.reload(true)) + case _ => ZIO.unit + }