Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Skeuomorph Integration - Part 1 #54

Merged
merged 17 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ project/target
# metals
.metals/
project/.bloop/
.bloop/
JesusMtnez marked this conversation as resolved.
Show resolved Hide resolved

.DS_Store
28 changes: 14 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ lazy val V = new {
val kindProjector: String = "0.10.3"
val paradise: String = "2.1.1"
val scala: String = "2.12.8"
val skeumorph: String = "0.0.1"
val skeumorph: String = "0.0.10"
val specs2: String = "4.6.0"
val enumeratum: String = "1.5.13"
val enumeratumCirce: String = "1.5.21"
Expand Down Expand Up @@ -122,7 +122,7 @@ lazy val commonSettings = Seq(
"org.typelevel" %% "mouse" % V.mouse,
%%("shapeless", V.shapeless),
%%("pureconfig", V.pureConfig),
"io.frees" %% "skeuomorph" % V.skeumorph,
"io.higherkindness" %% "skeuomorph" % V.skeumorph,
%%("http4s-dsl", V.http4s),
%%("http4s-blaze-server", V.http4s),
%%("http4s-circe", V.http4s),
Expand All @@ -131,15 +131,15 @@ lazy val commonSettings = Seq(
%%("doobie-core", V.doobie),
%%("doobie-postgres", V.doobie),
%%("doobie-hikari", V.doobie),
"com.beachape" %% "enumeratum" % V.enumeratum,
"com.beachape" %% "enumeratum-circe" % V.enumeratumCirce,
"org.flywaydb" % "flyway-core" % V.flyway,
"com.beachape" %% "enumeratum" % V.enumeratum,
Yawolf marked this conversation as resolved.
Show resolved Hide resolved
"com.beachape" %% "enumeratum-circe" % V.enumeratumCirce,
"org.flywaydb" % "flyway-core" % V.flyway,
%%("specs2-core", V.specs2) % Test,
%%("specs2-scalacheck", V.specs2) % Test,
%%("doobie-specs2", V.doobie) % Test,
"io.chrisdavenport" %% "cats-scalacheck" % V.catsScalacheck % Test,
"io.chrisdavenport" %% "testcontainers-specs2" % "0.1.0" % Test,
"org.testcontainers" % "postgresql" % "1.11.3" % Test
"io.chrisdavenport" %% "cats-scalacheck" % V.catsScalacheck % Test,
"io.chrisdavenport" %% "testcontainers-specs2" % "0.1.0" % Test,
"org.testcontainers" % "postgresql" % "1.11.3" % Test
),
orgScriptTaskListSetting := List(
(clean in Global).asRunnableItemFull,
Expand Down Expand Up @@ -174,19 +174,19 @@ lazy val commonSettings = Seq(
//Settings
lazy val clientSettings = Seq(
libraryDependencies ++= Seq(
"com.pepegar" %% "hammock-core" % V.hammock,
"com.pepegar" %% "hammock-core" % V.hammock,
"com.pepegar" %% "hammock-asynchttpclient" % V.hammock,
"com.pepegar" %% "hammock-circe" % V.hammock
"com.pepegar" %% "hammock-circe" % V.hammock
)
)

lazy val serverSettings = Seq(
parallelExecution in Test := false,
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-simple" % "1.7.26",
"eu.timepit" %% "refined" % V.refined,
"eu.timepit" %% "refined-scalacheck" % V.refined,
"io.chrisdavenport" %% "cats-scalacheck" % V.catsScalacheck % Test
"org.slf4j" % "slf4j-simple" % "1.7.26",
"eu.timepit" %% "refined" % V.refined,
"eu.timepit" %% "refined-scalacheck" % V.refined,
"io.chrisdavenport" %% "cats-scalacheck" % V.catsScalacheck % Test,
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2018-2019 47 Degrees, LLC. <http://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package higherkindness.compendium.models

import enumeratum.EnumEntry.Lowercase
import enumeratum.{EnumEntry, _}
Yawolf marked this conversation as resolved.
Show resolved Hide resolved

sealed trait IdlNames extends EnumEntry
Yawolf marked this conversation as resolved.
Show resolved Hide resolved

object IdlNames extends Enum[IdlNames] with CirceEnum[IdlNames] {
val values = findValues

case object Avro extends IdlNames with Lowercase
case object Protobuf extends IdlNames with Lowercase
case object Mu extends IdlNames with Lowercase
case object OpenApi extends IdlNames with Lowercase
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2018-2019 47 Degrees, LLC. <http://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package higherkindness.compendium.models

final case class MetaProtocolDB(idlName: IdlNames, id: String)
final case class MetaProtocol(idlName: IdlNames, protocol: Protocol)
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
package higherkindness.compendium.models

import enumeratum._
import enumeratum.EnumEntry._

sealed trait Target extends EnumEntry

object Target extends Enum[Target] {

val values = findValues

case object Scala extends Target
case object Scala extends Target with Lowercase
case object Protobuf extends Target with Lowercase
case object Avro extends Target with Lowercase
case object Mu extends Target with Lowercase
case object OpenApi extends Target with Lowercase
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CREATE TABLE protocols (
id VARCHAR PRIMARY KEY
)
id VARCHAR PRIMARY KEY,
idl_name VARCHAR NOT NULL
Yawolf marked this conversation as resolved.
Show resolved Hide resolved
);
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import higherkindness.compendium.db._
import higherkindness.compendium.http._
import higherkindness.compendium.migrations.Migrations
import higherkindness.compendium.models.config._
import higherkindness.compendium.parser.{ProtocolParser, ProtocolParserService}
import higherkindness.compendium.storage._
import org.http4s.server.Router
import pureconfig.generic.auto._
Expand All @@ -45,13 +46,14 @@ object CompendiumStreamApp {
)
_ <- Stream.eval(Migrations.makeMigrations(conf.postgres))
transactor <- Stream.resource(createTransactor(conf.postgres))
implicit0(storage: Storage[F]) = FileStorage.impl[F](conf.storage)
implicit0(dbService: DBService[F]) = PgDBService.impl[F](transactor)
implicit0(utils: ProtocolUtils[F]) = ProtocolUtils.impl[F]
implicit0(compendiumService: CompendiumService[F]) = CompendiumService.impl[F]
rootService = RootService.rootRouteService
healthService = HealthService.healthRouteService
app = Router("/" -> healthService, "/v0" -> rootService)
implicit0(storage: Storage[F]) = FileStorage.impl[F](conf.storage)
implicit0(dbService: DBService[F]) = PgDBService.impl[F](transactor)
implicit0(utils: ProtocolUtils[F]) = ProtocolUtils.impl[F]
implicit0(protocolParser: ProtocolParserService[F]) = ProtocolParser.impl[F]
implicit0(compendiumService: CompendiumService[F]) = CompendiumService.impl[F]
rootService = RootService.rootRouteService
healthService = HealthService.healthRouteService
app = Router("/" -> healthService, "/v0" -> rootService)
code <- CompendiumServerStream.serverStream(conf.http, app)
} yield code

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,43 @@ import cats.effect.Sync
import cats.implicits._
import higherkindness.compendium.core.refinements.ProtocolId
import higherkindness.compendium.db.DBService
import higherkindness.compendium.models.Protocol
import higherkindness.compendium.models.{IdlNames, MetaProtocol, Protocol, Target}
import higherkindness.compendium.models.parserModels.ParserResult
import higherkindness.compendium.parser.ProtocolParserService
import higherkindness.compendium.storage.Storage

trait CompendiumService[F[_]] {

def storeProtocol(id: ProtocolId, protocol: Protocol): F[Unit]
def recoverProtocol(protocolId: ProtocolId): F[Option[Protocol]]
def storeProtocol(id: ProtocolId, protocol: Protocol, idlName: IdlNames): F[Unit]
def recoverProtocol(protocolId: ProtocolId): F[Option[MetaProtocol]]
def existsProtocol(protocolId: ProtocolId): F[Boolean]
def parseProtocol(protocolName: ProtocolId, target: Target): F[ParserResult]
}

object CompendiumService {

implicit def impl[F[_]: Sync: Storage: DBService: ProtocolUtils](): CompendiumService[F] =
implicit def impl[F[_]: Sync: Storage: DBService: ProtocolUtils: ProtocolParserService](): CompendiumService[
F] =
new CompendiumService[F] {

override def storeProtocol(id: ProtocolId, protocol: Protocol): F[Unit] =
override def storeProtocol(id: ProtocolId, protocol: Protocol, idlName: IdlNames): F[Unit] =
ProtocolUtils[F].validateProtocol(protocol) >>
DBService[F].upsertProtocol(id) >>
DBService[F].upsertProtocol(id, idlName) >>
Storage[F].store(id, protocol)

override def recoverProtocol(protocolId: ProtocolId): F[Option[Protocol]] =
override def recoverProtocol(protocolId: ProtocolId): F[Option[MetaProtocol]] =
DBService[F]
.existsProtocol(protocolId)
.ifM(Storage[F].recover(protocolId), none[Protocol].pure[F])
.selectProtocolById(protocolId)
Yawolf marked this conversation as resolved.
Show resolved Hide resolved
.flatMap(mpdb => Storage[F].recover(mpdb))
Yawolf marked this conversation as resolved.
Show resolved Hide resolved

override def existsProtocol(protocolId: ProtocolId): F[Boolean] =
DBService[F].existsProtocol(protocolId)

override def parseProtocol(protocolName: ProtocolId, target: Target): F[ParserResult] =
for {
protocol <- recoverProtocol(protocolName)
parsedProtocol <- ProtocolParserService[F].parse(protocol, target)
} yield parsedProtocol
}

def apply[F[_]](implicit F: CompendiumService[F]): CompendiumService[F] = F
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package higherkindness.compendium.db

import higherkindness.compendium.models.{IdlNames, MetaProtocolDB}
import higherkindness.compendium.core.refinements.ProtocolId

trait DBService[F[_]] {
def upsertProtocol(id: ProtocolId): F[Unit]
def upsertProtocol(id: ProtocolId, idlName: IdlNames): F[Unit]
def existsProtocol(id: ProtocolId): F[Boolean]
def selectProtocolById(id: ProtocolId): F[MetaProtocolDB]
Yawolf marked this conversation as resolved.
Show resolved Hide resolved
def ping(): F[Boolean]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ import doobie.util.transactor.Transactor
import doobie.implicits._
import higherkindness.compendium.core.refinements.ProtocolId
import higherkindness.compendium.db.queries.Queries
import higherkindness.compendium.models.{IdlNames, MetaProtocolDB}

object PgDBService {

def impl[F[_]: Async](xa: Transactor[F]): DBService[F] =
new DBService[F] {

override def upsertProtocol(id: ProtocolId): F[Unit] =
Queries.upsertProtocolIdQ(id.value).run.void.transact(xa)
override def upsertProtocol(id: ProtocolId, idlName: IdlNames): F[Unit] =
Queries.upsertProtocolIdQ(id.value, idlName.entryName).run.void.transact(xa)

override def existsProtocol(id: ProtocolId): F[Boolean] =
Queries.checkIfExistsQ(id.value).unique.transact(xa)

override def selectProtocolById(id: ProtocolId): F[MetaProtocolDB] =
Yawolf marked this conversation as resolved.
Show resolved Hide resolved
Queries.selectProtocolById(id.value).unique.transact(xa)
Yawolf marked this conversation as resolved.
Show resolved Hide resolved

override def ping(): F[Boolean] = Queries.checkConnection().unique.transact(xa)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package higherkindness.compendium.db.queries

import doobie._
import doobie.implicits.toSqlInterpolator
import higherkindness.compendium.models.MetaProtocolDB
import metas._

object Queries {

Expand All @@ -26,13 +28,18 @@ object Queries {
SELECT exists (SELECT true FROM protocols WHERE id=$id)
""".query[Boolean]

def upsertProtocolIdQ(id: String): Update0 =
def upsertProtocolIdQ(id: String, idl_name: String): Update0 =
sql"""
INSERT INTO protocols
VALUES ($id)
INSERT INTO protocols (id, idl_name)
VALUES ($id, $idl_name)
ON CONFLICT DO NOTHING
""".update

def selectProtocolById(id: String): Query0[MetaProtocolDB] =
sql"""
SELECT * from protocols WHERE id=$id
""".query[MetaProtocolDB]

def checkConnection(): Query0[Boolean] =
sql"SELECT exists (SELECT 1)".query[Boolean]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2018-2019 47 Degrees, LLC. <http://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package higherkindness.compendium.db.queries

import doobie.util.Meta
import higherkindness.compendium.models.IdlNames

object metas {

implicit val IdlNamesMeta: Meta[IdlNames] = Meta[String].timap(IdlNames.withName)(_.entryName)
Yawolf marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@

package higherkindness.compendium.http

import higherkindness.compendium.models.Target
import higherkindness.compendium.models.{IdlNames, Target}
import org.http4s.QueryParamDecoder
import org.http4s.dsl.impl.QueryParamDecoderMatcher

object QueryParams {

implicit val queryTargetDecoderQueryParam: QueryParamDecoder[Target] =
QueryParamDecoder[String].map(_ => Target.Scala)
QueryParamDecoder[String].map(Target.withName)
Yawolf marked this conversation as resolved.
Show resolved Hide resolved

object TargetQueryParam extends QueryParamDecoderMatcher[Target]("target")

implicit val queryIdlDecoderQueryParam: QueryParamDecoder[IdlNames] =
QueryParamDecoder[String].map(IdlNames.withName)

object IdlQueryParam extends QueryParamDecoderMatcher[IdlNames]("idlName")

}
Loading