diff --git a/.mergify.yml b/.mergify.yml index 401a024c..481d64c3 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -18,8 +18,7 @@ pull_request_rules: conditions: - author=scala-steward - "body~=(labels: library-update, early-semver-minor)|(labels: library-update, early-semver-patch)|(labels: sbt-plugin-update, early-semver-minor)|(labels: sbt-plugin-update, early-semver-patch)|(labels: test-library-update)" - - "check-success=Java8" - - "check-success=Java11" + - "check-success=ci" actions: merge: method: squash diff --git a/.scalafmt.conf b/.scalafmt.conf index 07cf0568..1d937a4e 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = "3.7.12" +version = "3.7.14" runner.dialect = scala213 maxColumn = 120 align.preset = more diff --git a/README.md b/README.md index 3bfec750..0d00cba5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ +
+ # zim +[![Project stage](https://img.shields.io/badge/Project%20Stage-Concept-orange.svg)](https://github.com/bitlap/bitlap/wiki/Project-Stages) [![Build](https://github.com/bitlap/zim/actions/workflows/ScalaCI.yml/badge.svg?branch=master)](https://github.com/bitlap/zim/actions/workflows/ScalaCI.yml) [![codecov](https://codecov.io/gh/bitlap/zim/branch/master/graph/badge.svg?token=V95ZMWUUCE)](https://codecov.io/gh/bitlap/zim) [![Docker Image Version (latest semver)](https://img.shields.io/docker/v/liguobin/zim?label=docker-image)](https://hub.docker.com/r/liguobin/zim/tags) diff --git a/logo.png b/logo.png new file mode 100644 index 00000000..e67867dc Binary files /dev/null and b/logo.png differ diff --git a/modules/zim-cache-redis4cats/src/main/scala/org/bitlap/zim/cache/redis4cats/CatsRedisServiceLive.scala b/modules/zim-cache-redis4cats/src/main/scala/org/bitlap/zim/cache/redis4cats/CatsRedisServiceLive.scala index 3f43a54c..68734bc9 100644 --- a/modules/zim-cache-redis4cats/src/main/scala/org/bitlap/zim/cache/redis4cats/CatsRedisServiceLive.scala +++ b/modules/zim-cache-redis4cats/src/main/scala/org/bitlap/zim/cache/redis4cats/CatsRedisServiceLive.scala @@ -71,7 +71,7 @@ object CatsRedisServiceLive { redis <- Redis[IO].fromClient(client, stringCodec) } yield redis - lazy val live: ULayer[CRedis] = ZLayer.succeed(new CatsRedisServiceLive(resource)) + lazy val live: ULayer[Redis] = ZLayer.succeed(new CatsRedisServiceLive(resource)) } final case class CatsRedisServiceLive(redis: Resource[IO, RedisCommands[IO, String, String]])(implicit diff --git a/modules/zim-cache-redis4cats/src/main/scala/org/bitlap/zim/cache/redis4cats/package.scala b/modules/zim-cache-redis4cats/src/main/scala/org/bitlap/zim/cache/redis4cats/package.scala index 51686e38..c32b023f 100644 --- a/modules/zim-cache-redis4cats/src/main/scala/org/bitlap/zim/cache/redis4cats/package.scala +++ b/modules/zim-cache-redis4cats/src/main/scala/org/bitlap/zim/cache/redis4cats/package.scala @@ -23,5 +23,5 @@ import cats.effect.IO * @version 1.0,2023/3/26 */ package object redis4cats { - type CRedis = RedisService[IO] + type Redis = RedisService[IO] } diff --git a/modules/zim-infra/src/main/scala/org/bitlap/zim/infrastructure/InfrastructureConfiguration.scala b/modules/zim-infra/src/main/scala/org/bitlap/zim/infrastructure/InfrastructureConfiguration.scala index ef1bc768..f602ef6e 100644 --- a/modules/zim-infra/src/main/scala/org/bitlap/zim/infrastructure/InfrastructureConfiguration.scala +++ b/modules/zim-infra/src/main/scala/org/bitlap/zim/infrastructure/InfrastructureConfiguration.scala @@ -32,19 +32,23 @@ import zio._ */ final class InfrastructureConfiguration { - ConnectionPool.add( - Symbol(mysqlConfigurationProperties.databaseName), - mysqlConfigurationProperties.url, - mysqlConfigurationProperties.user, - mysqlConfigurationProperties.password, - ConnectionPoolSettings( - initialSize = mysqlConfigurationProperties.initialSize, - maxSize = mysqlConfigurationProperties.maxSize, - connectionTimeoutMillis = mysqlConfigurationProperties.connectionTimeoutMillis, - validationQuery = mysqlConfigurationProperties.validationQuery, - driverName = mysqlConfigurationProperties.driverName - ) - ) + def initPool(): URIO[Any, Unit] = { + ZIO.attempt { + ConnectionPool.add( + Symbol(mysqlConfigurationProperties.databaseName), + mysqlConfigurationProperties.url, + mysqlConfigurationProperties.user, + mysqlConfigurationProperties.password, + ConnectionPoolSettings( + initialSize = mysqlConfigurationProperties.initialSize, + maxSize = mysqlConfigurationProperties.maxSize, + connectionTimeoutMillis = mysqlConfigurationProperties.connectionTimeoutMillis, + validationQuery = mysqlConfigurationProperties.validationQuery, + driverName = mysqlConfigurationProperties.driverName + ) + ) + }.orDie + } lazy val mysqlConfigurationProperties: MysqlConfigurationProperties = MysqlConfigurationProperties() diff --git a/modules/zim-server/src/main/scala/org/bitlap/zim/server/ZimServer.scala b/modules/zim-server/src/main/scala/org/bitlap/zim/server/ZimServer.scala index f8b2d938..3525213c 100644 --- a/modules/zim-server/src/main/scala/org/bitlap/zim/server/ZimServer.scala +++ b/modules/zim-server/src/main/scala/org/bitlap/zim/server/ZimServer.scala @@ -45,7 +45,8 @@ object ZimServer extends zio.ZIOAppDefault { | ./__; .' | | '.'|| | |`-' | ; | .' ; : ;| ;/ | `---' | , / '---'""".stripMargin) - _ <- ZIO.environmentWithZIO[AkkaHttpModule](_.get.httpServer()) + _ <- ZIO.serviceWithZIO[InfrastructureConfiguration](_.initPool()) // init pool + _ <- ZIO.serviceWithZIO[AkkaHttpModule](_.httpServer()) _ <- ZIO.never } yield ()).provide( AkkaModule.live, diff --git a/modules/zim-server/src/main/scala/org/bitlap/zim/server/module/AkkaModule.scala b/modules/zim-server/src/main/scala/org/bitlap/zim/server/module/AkkaModule.scala index 9040d367..fab420ec 100644 --- a/modules/zim-server/src/main/scala/org/bitlap/zim/server/module/AkkaModule.scala +++ b/modules/zim-server/src/main/scala/org/bitlap/zim/server/module/AkkaModule.scala @@ -37,10 +37,10 @@ object AkkaModule { lazy val live: ZLayer[Any with Any with Scope, Throwable, ActorSystem[Nothing]] = ZLayer.fromZIO(ZIO.acquireRelease(ZIO.attempt(akkaActorSystem))(a => ZIO.attempt(a.terminate()).ignore)) - lazy val wslive: ZLayer[Any, Throwable, ActorSystem[Nothing]] = + private lazy val actorSystemLive: ZLayer[Any, Throwable, ActorSystem[Nothing]] = ZLayer.fromZIO(ZIO.attempt(wsAkkaActorSystem)) def make: ZIO[Any, Throwable, ActorSystem[Nothing]] = Scope.global.use { - ZIO.service[ActorSystem[Nothing]].provideLayer(wslive) + ZIO.service[ActorSystem[Nothing]].provideLayer(actorSystemLive) } } diff --git a/modules/zim-server/src/main/scala/org/bitlap/zim/server/service/MailServiceImpl.scala b/modules/zim-server/src/main/scala/org/bitlap/zim/server/service/MailServiceImpl.scala index d4205bb0..4cc0b20a 100644 --- a/modules/zim-server/src/main/scala/org/bitlap/zim/server/service/MailServiceImpl.scala +++ b/modules/zim-server/src/main/scala/org/bitlap/zim/server/service/MailServiceImpl.scala @@ -68,7 +68,7 @@ object MailServiceImpl { ) def sendHtmlMail(to: String, subject: String, content: String): URIO[MailServiceImpl, Any] = - ZIO.environmentWithZIO(_.get.sendHtmlMail(to, subject, content)) + ZIO.serviceWithZIO(_.sendHtmlMail(to, subject, content)) lazy val live: URLayer[MailConfigurationProperties, MailServiceImpl] = ZLayer( ZIO.service[MailConfigurationProperties].map(MailServiceImpl.apply) diff --git a/modules/zim-server/src/main/scala/org/bitlap/zim/server/service/RedisCache.scala b/modules/zim-server/src/main/scala/org/bitlap/zim/server/service/RedisCache.scala index 648042fd..449221ab 100644 --- a/modules/zim-server/src/main/scala/org/bitlap/zim/server/service/RedisCache.scala +++ b/modules/zim-server/src/main/scala/org/bitlap/zim/server/service/RedisCache.scala @@ -16,7 +16,7 @@ package org.bitlap.zim.server.service -import org.bitlap.zim.cache.redis4cats.{CatsRedisServiceLive, CRedis} +import org.bitlap.zim.cache.redis4cats.{CatsRedisServiceLive, Redis} import org.bitlap.zim.cache.redis4zio._ import org.bitlap.zim.server.CacheType import org.bitlap.zim.server.CacheType._ @@ -34,7 +34,7 @@ object RedisCache { def getSets(k: String)(implicit cacheType: CacheType): Task[List[String]] = cacheType match { case ZioCache => ZIO.serviceWithZIO[ZRedis](_.getSets(k)).provideLayer(ZioRedisServiceLive.live) case CatsCache => - ZIO.serviceWithZIO[CRedis](c => LiftIO.liftK[Task].apply(c.getSets(k))).provideLayer(CatsRedisServiceLive.live) + ZIO.serviceWithZIO[Redis](c => LiftIO.liftK[Task].apply(c.getSets(k))).provideLayer(CatsRedisServiceLive.live) } def removeSetValue(k: String, m: String)(implicit cacheType: CacheType): Task[Long] = cacheType match { @@ -42,7 +42,7 @@ object RedisCache { ZIO.serviceWithZIO[ZRedis](_.removeSetValue(k, m)).provideLayer(ZioRedisServiceLive.live) case CatsCache => ZIO - .serviceWithZIO[CRedis](c => LiftIO.liftK[Task].apply(c.removeSetValue(k, m))) + .serviceWithZIO[Redis](c => LiftIO.liftK[Task].apply(c.removeSetValue(k, m))) .provideLayer(CatsRedisServiceLive.live) } @@ -51,7 +51,7 @@ object RedisCache { case ZioCache => ZIO.serviceWithZIO[ZRedis](_.setSet(k, m)).provideLayer(ZioRedisServiceLive.live) case CatsCache => ZIO - .serviceWithZIO[CRedis](c => LiftIO.liftK[Task].apply(c.setSet(k, m))) + .serviceWithZIO[Redis](c => LiftIO.liftK[Task].apply(c.setSet(k, m))) .provideLayer(CatsRedisServiceLive.live) } @@ -64,7 +64,7 @@ object RedisCache { ZIO.serviceWithZIO[ZRedis](_.set[T](key, value)).provideLayer(ZioRedisServiceLive.live) case CatsCache => ZIO - .serviceWithZIO[CRedis](c => LiftIO.liftK[Task].apply(c.set(key, value))) + .serviceWithZIO[Redis](c => LiftIO.liftK[Task].apply(c.set(key, value))) .provideLayer(CatsRedisServiceLive.live) } @@ -76,20 +76,20 @@ object RedisCache { case ZioCache => ZIO.serviceWithZIO[ZRedis](_.get[T](key)).provideLayer(ZioRedisServiceLive.live) case CatsCache => - ZIO.serviceWithZIO[CRedis](c => LiftIO.liftK[Task].apply(c.get(key))).provideLayer(CatsRedisServiceLive.live) + ZIO.serviceWithZIO[Redis](c => LiftIO.liftK[Task].apply(c.get(key))).provideLayer(CatsRedisServiceLive.live) } def exists(key: String)(implicit cacheType: CacheType): Task[Boolean] = cacheType match { case ZioCache => ZIO.serviceWithZIO[ZRedis](_.exists(key)).provideLayer(ZioRedisServiceLive.live) case CatsCache => - ZIO.serviceWithZIO[CRedis](c => LiftIO.liftK[Task].apply(c.exists(key))).provideLayer(CatsRedisServiceLive.live) + ZIO.serviceWithZIO[Redis](c => LiftIO.liftK[Task].apply(c.exists(key))).provideLayer(CatsRedisServiceLive.live) } def del(key: String)(implicit cacheType: CacheType): Task[Boolean] = cacheType match { case ZioCache => ZIO.serviceWithZIO[ZRedis](_.del(key)).provideLayer(ZioRedisServiceLive.live) case CatsCache => - ZIO.serviceWithZIO[CRedis](c => LiftIO.liftK[Task].apply(c.del(key))).provideLayer(CatsRedisServiceLive.live) + ZIO.serviceWithZIO[Redis](c => LiftIO.liftK[Task].apply(c.del(key))).provideLayer(CatsRedisServiceLive.live) } } diff --git a/modules/zim-server/src/main/scala/org/bitlap/zim/server/service/ws/WsService.scala b/modules/zim-server/src/main/scala/org/bitlap/zim/server/service/ws/WsService.scala index 90be9909..a65275cf 100644 --- a/modules/zim-server/src/main/scala/org/bitlap/zim/server/service/ws/WsService.scala +++ b/modules/zim-server/src/main/scala/org/bitlap/zim/server/service/ws/WsService.scala @@ -48,12 +48,13 @@ import zio.actors.akka._ */ object WsService { - private lazy val wsLayer = - InfrastructureConfiguration.live >>> UserServiceImpl.live >>> WsServiceLive.live + private lazy val wsLayer: ZLayer[Any, Throwable, WsServiceLive] = { + ZLayer.make[WsServiceLive](InfrastructureConfiguration.live, UserServiceImpl.live, WsServiceLive.live) + } final lazy val actorRefSessions: ConcurrentHashMap[Integer, ActorRef] = new ConcurrentHashMap[Integer, ActorRef] - private val customDispatcher = DispatcherSelector.fromConfig("custom-dispatcher") + private val customDispatcher: DispatcherSelector = DispatcherSelector.fromConfig("custom-dispatcher") // 非最佳实践,为了使用unsafeRun,不能把environment传递到最外层,这里直接provideLayer def sendMessage(message: IMMessage): Task[Unit] = diff --git a/project/Dependencies.scala b/project/Dependencies.scala index e3947e6b..ee305cd9 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -8,24 +8,24 @@ import sbt._ object Dependencies { object Version { - val zio = "2.0.16" + val zio = "2.0.18" val `zio-logging` = "2.1.14" val tapir = "1.7.0" val `akka-http` = "10.5.0" val akka = "2.8.0" val circe = "0.14.3" - val scalikejdbc = "4.0.0" + val scalikejdbc = "4.1.0" val logback = "1.4.11" - val config = "1.4.2" + val config = "1.4.3" val `zio-interop-reactiveStreams` = "2.0.2" val mysql = "8.0.32" val `simple-java-mail` = "7.5.0" - val h2 = "2.2.220" - val scalaTest = "3.2.15" + val h2 = "2.2.224" + val scalaTest = "3.2.17" val `zio-actors` = "0.1.0" val refined = "0.10.3" - val `zio-schema` = "0.4.13" - val `sttp-apispec` = "0.6.0" + val `zio-schema` = "0.4.14" + val `sttp-apispec` = "0.6.3" val redis4cats = "1.4.1" val `zio-interop-cats` = "23.0.03" val `log4cats-slf4j` = "2.5.0" diff --git a/project/build.properties b/project/build.properties index 0ac3d3f0..4790c797 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version = 1.9.4 \ No newline at end of file +sbt.version = 1.9.6 \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index 13265760..97ad4e8e 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,7 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.2") -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8") +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9") //addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.1") addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.16") addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.9.0") diff --git a/version.sbt b/version.sbt index b3ce6e3c..5f944c1b 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -ThisBuild / version := "0.6.3" +ThisBuild / version := "0.6.4"