diff --git a/build.sbt b/build.sbt index 1797823f5..13e561c2a 100644 --- a/build.sbt +++ b/build.sbt @@ -28,18 +28,19 @@ lazy val root = lazy val library = project .in(file("modules/library")) + .disablePlugins(RevolverPlugin) .settings(stdSettings("zio-elasticsearch")) .settings(scalacOptions += "-language:higherKinds") .configs(IntegrationTest) .settings( Defaults.itSettings, libraryDependencies ++= List( - "com.softwaremill.sttp.client3" %% "zio" % "3.8.3", - "com.softwaremill.sttp.client3" %% "zio-json" % "3.8.3", + "com.softwaremill.sttp.client3" %% "zio" % "3.8.5", + "com.softwaremill.sttp.client3" %% "zio-json" % "3.8.5", "dev.zio" %% "zio-json" % "0.3.0", "dev.zio" %% "zio-prelude" % "1.0.0-RC16", - "dev.zio" %% "zio-schema" % "0.3.1", - "dev.zio" %% "zio-schema-json" % "0.3.1", + "dev.zio" %% "zio-schema" % "0.4.1", + "dev.zio" %% "zio-schema-json" % "0.4.1", "org.apache.commons" % "commons-lang3" % "3.12.0", "dev.zio" %% "zio-test" % "2.0.5" % Tests, "dev.zio" %% "zio-test-sbt" % "2.0.5" % Tests @@ -55,13 +56,13 @@ lazy val example = .settings( libraryDependencies ++= List( "dev.zio" %% "zio" % "2.0.5", - "dev.zio" %% "zio-config" % "3.0.2", - "dev.zio" %% "zio-config-magnolia" % "3.0.2", - "dev.zio" %% "zio-config-typesafe" % "3.0.2", + "dev.zio" %% "zio-config" % "3.0.6", + "dev.zio" %% "zio-config-magnolia" % "3.0.6", + "dev.zio" %% "zio-config-typesafe" % "3.0.6", "dev.zio" %% "zio-http" % "0.0.3", "dev.zio" %% "zio-json" % "0.3.0", - "dev.zio" %% "zio-schema" % "0.3.1", - "dev.zio" %% "zio-schema-json" % "0.3.1" + "dev.zio" %% "zio-schema" % "0.4.1", + "dev.zio" %% "zio-schema-json" % "0.4.1" ) ) .dependsOn(library) @@ -73,6 +74,7 @@ lazy val docs = project .in(file("modules/docs")) .enablePlugins(MdocPlugin, DocusaurusPlugin, ScalaUnidocPlugin) + .disablePlugins(RevolverPlugin) .dependsOn(library) .settings( publish / skip := true, diff --git a/modules/example/README.md b/modules/example/README.md index dc13d0fb1..b16a9b3f0 100644 --- a/modules/example/README.md +++ b/modules/example/README.md @@ -8,7 +8,7 @@ This application represents an example of usage `zio-elasticsearch` library for repository) - Start the application by running the following command: ```shell - ./sbt example/run + ./sbt "~example/reStart" ``` - Check whether the application is running [here](http://localhost:9000/health) - Explore endpoints using Postman collection (`zio-elasticsearch-example.postman_collection.json`) diff --git a/modules/example/src/main/scala/example/Repository.scala b/modules/example/src/main/scala/example/GitHubRepo.scala similarity index 60% rename from modules/example/src/main/scala/example/Repository.scala rename to modules/example/src/main/scala/example/GitHubRepo.scala index d31086b43..a5e7ccf09 100644 --- a/modules/example/src/main/scala/example/Repository.scala +++ b/modules/example/src/main/scala/example/GitHubRepo.scala @@ -5,7 +5,7 @@ import zio.schema.{DeriveSchema, Schema} import java.time.LocalDateTime -final case class Repository( +final case class GitHubRepo( id: Option[String], organization: String, name: String, @@ -16,8 +16,8 @@ final case class Repository( forks: Int ) -object Repository { - implicit val schema: Schema[Repository] = DeriveSchema.gen[Repository] +object GitHubRepo { + implicit val schema: Schema[GitHubRepo] = DeriveSchema.gen[GitHubRepo] - implicit val encoder: JsonEncoder[Repository] = DeriveJsonEncoder.gen[Repository] + implicit val encoder: JsonEncoder[GitHubRepo] = DeriveJsonEncoder.gen[GitHubRepo] } diff --git a/modules/example/src/main/scala/example/Main.scala b/modules/example/src/main/scala/example/Main.scala index 958062248..2c5d3039a 100644 --- a/modules/example/src/main/scala/example/Main.scala +++ b/modules/example/src/main/scala/example/Main.scala @@ -13,10 +13,14 @@ import scala.io.Source object Main extends ZIOAppDefault { override def run: Task[ExitCode] = { - val elasticConfigLive = ZLayer(getConfig[ElasticsearchConfig].map(es => ElasticConfig(es.host, es.port))) - val elasticExecutorLive = elasticConfigLive >>> ElasticExecutor.live + val elasticConfigLive = ZLayer(getConfig[ElasticsearchConfig].map(es => ElasticConfig(es.host, es.port))) - (prepare *> runServer).provide(AppConfig.live, elasticExecutorLive, HttpClientZioBackend.layer()) + (prepare *> runServer).provide( + AppConfig.live, + elasticConfigLive, + ElasticExecutor.live, + HttpClientZioBackend.layer() + ) } private[this] def prepare: RIO[ElasticExecutor, Unit] = { diff --git a/modules/example/src/main/scala/example/RepositoriesElasticsearch.scala b/modules/example/src/main/scala/example/RepositoriesElasticsearch.scala index 003c7bfac..4566737d4 100644 --- a/modules/example/src/main/scala/example/RepositoriesElasticsearch.scala +++ b/modules/example/src/main/scala/example/RepositoriesElasticsearch.scala @@ -7,20 +7,20 @@ import zio.{RIO, ULayer, ZIO, ZLayer} final class RepositoriesElasticsearch { - def findById(organization: String, id: String): RIO[ElasticExecutor, Option[Repository]] = + def findById(organization: String, id: String): RIO[ElasticExecutor, Option[GitHubRepo]] = ElasticRequest - .getById[Repository](Index, DocumentId(id)) + .getById[GitHubRepo](Index, DocumentId(id)) .routing(unsafeWrap(Routing)(organization)) .execute .map(_.toOption) - def create(repository: Repository): RIO[ElasticExecutor, Option[DocumentId]] = + def create(repository: GitHubRepo): RIO[ElasticExecutor, Option[DocumentId]] = ElasticRequest .create(Index, repository) .routing(unsafeWrap(Routing)(repository.organization)) .execute - def upsert(id: String, repository: Repository): RIO[ElasticExecutor, Unit] = + def upsert(id: String, repository: GitHubRepo): RIO[ElasticExecutor, Unit] = ElasticRequest .upsert(Index, DocumentId(id), repository) .routing(unsafeWrap(Routing)(repository.organization)) @@ -40,13 +40,13 @@ object RepositoriesElasticsearch { def findById( organization: String, id: String - ): RIO[ElasticExecutor with RepositoriesElasticsearch, Option[Repository]] = + ): RIO[ElasticExecutor with RepositoriesElasticsearch, Option[GitHubRepo]] = ZIO.serviceWithZIO[RepositoriesElasticsearch](_.findById(organization, id)) - def create(repository: Repository): RIO[ElasticExecutor with RepositoriesElasticsearch, Option[DocumentId]] = + def create(repository: GitHubRepo): RIO[ElasticExecutor with RepositoriesElasticsearch, Option[DocumentId]] = ZIO.serviceWithZIO[RepositoriesElasticsearch](_.create(repository)) - def upsert(id: String, repository: Repository): RIO[ElasticExecutor with RepositoriesElasticsearch, Unit] = + def upsert(id: String, repository: GitHubRepo): RIO[ElasticExecutor with RepositoriesElasticsearch, Unit] = ZIO.serviceWithZIO[RepositoriesElasticsearch](_.upsert(id, repository)) def remove( diff --git a/modules/example/src/main/scala/example/api/Application.scala b/modules/example/src/main/scala/example/api/Application.scala index 8c573dfb2..24c8576d2 100644 --- a/modules/example/src/main/scala/example/api/Application.scala +++ b/modules/example/src/main/scala/example/api/Application.scala @@ -2,12 +2,12 @@ package example.api import zio.http._ import zio.http.model.Method -import zio.json.ast.Json +import zio.json.ast.Json._ object Application { final val Routes: Http[Any, Nothing, Any, Response] = Http.collect { case Method.GET -> !! / "health" => - Response.json(Json.Obj("name" -> Json.Str("zio-elasticsearch-example"), "status" -> Json.Str("up")).toJson) + Response.json(Obj("name" -> Str("zio-elasticsearch-example"), "status" -> Str("up")).toJson) } } diff --git a/modules/example/src/main/scala/example/api/Repositories.scala b/modules/example/src/main/scala/example/api/Repositories.scala index 3b6d76f2b..10636f5d0 100644 --- a/modules/example/src/main/scala/example/api/Repositories.scala +++ b/modules/example/src/main/scala/example/api/Repositories.scala @@ -1,6 +1,6 @@ package example.api -import example.{RepositoriesElasticsearch, Repository} +import example.{GitHubRepo, RepositoriesElasticsearch} import zio.ZIO import zio.elasticsearch.{DocumentId, ElasticExecutor} import zio.http._ @@ -31,7 +31,7 @@ object Repositories { case req @ Method.POST -> BasePath => req.body.asString - .map(JsonCodec.JsonDecoder.decode[Repository](Repository.schema, _)) + .map(JsonCodec.JsonDecoder.decode[GitHubRepo](GitHubRepo.schema, _)) .flatMap { case Left(e) => ZIO.succeed(Response.json(ErrorResponse.fromReasons(e.message).toJson).setStatus(BadRequest)) @@ -47,7 +47,7 @@ object Repositories { case req @ Method.PUT -> BasePath / id => req.body.asString - .map(JsonCodec.JsonDecoder.decode[Repository](Repository.schema, _)) + .map(JsonCodec.JsonDecoder.decode[GitHubRepo](GitHubRepo.schema, _)) .flatMap { case Left(e) => ZIO.succeed(Response.json(ErrorResponse.fromReasons(e.message).toJson).setStatus(BadRequest))