Skip to content

Commit

Permalink
chore: update scala 2.13 to 3.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MoeQuadrat committed Jan 16, 2024
1 parent d48d6dd commit 8b61f9c
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 91 deletions.
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ val githubSettings = Seq(
)
)

scalaVersion := "2.13.12"
scalaVersion := "3.3.1"

val defaultProjectSettings = Seq(
scalaVersion := "2.13.12",
scalaVersion := "3.3.1",
organization := "de.innfactory",
version := releaseVersion
) ++ githubSettings
Expand All @@ -41,7 +41,7 @@ lazy val smithy4play = project
Compile / smithy4sInputDirs := Seq(
(ThisBuild / baseDirectory).value / "smithy4play" / "src" / "resources" / "META_INF" / "smithy"
),
Compile / smithy4sOutputDir := (ThisBuild / baseDirectory).value / "smithy4play" / "target" / "scala-2.13" / "src_managed" / "main",
Compile / smithy4sOutputDir := (ThisBuild / baseDirectory).value / "smithy4play" / "target" / "scala-3.3.1" / "src_managed" / "main",
name := "smithy4play",
scalacOptions += "-Ymacro-annotations",
Compile / compile / wartremoverWarnings ++= Warts.unsafe,
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Dependencies {
val playVersion = "3.0.1"
val typesafePlay = "org.playframework" %% "play" % playVersion

val scalaVersion = "2.13.12"
val scalaVersion = "3.3.1"
val smithy4sVersion = "0.17.19"
val smithyCore = "com.disneystreaming.smithy4s" %% "smithy4s-core" % smithy4sVersion
val smithyJson = "com.disneystreaming.smithy4s" %% "smithy4s-json" % smithy4sVersion
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sbt.version = 1.9.8
scala.version = 2.13.2
scala.version = 3.3.1
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package de.innfactory.smithy4play

import cats.data.{ EitherT, Kleisli }
import cats.data.{EitherT, Kleisli}
import cats.implicits.toTraverseOps
import de.innfactory.smithy4play.middleware.MiddlewareBase
import play.api.mvc.{ AbstractController, ControllerComponents, Handler, RequestHeader }
import play.api.mvc.{AbstractController, ControllerComponents, Handler, RequestHeader}
import play.api.routing.Router.Routes
import smithy4s.HintMask
import smithy4s.http.{ HttpEndpoint, PathSegment }
import smithy4s.http.{HttpEndpoint, PathSegment}
import smithy4s.internals.InputOutput
import smithy4s.kinds.{ FunctorAlgebra, Kind1, PolyFunction5 }
import smithy4s.kinds.{FunctorAlgebra, Kind1, PolyFunction5}

import scala.concurrent.ExecutionContext

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.innfactory.smithy4play.middleware

import cats.data.Kleisli
import de.innfactory.smithy4play.{ EndpointResult, RouteResult, RoutingContext }
import de.innfactory.smithy4play.{RouteResult, RoutingContext}
import play.api.Logger

trait MiddlewareBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import smithy.api.{ Auth, HttpBearerAuth }

import javax.inject.{ Inject, Singleton }
import scala.concurrent.{ ExecutionContext, Future }

import smithy.api.AuthTraitReference.asBijection
@Singleton
class ValidateAuthMiddleware @Inject() (implicit
executionContext: ExecutionContext
) extends MiddlewareBase {

override protected def skipMiddleware(r: RoutingContext): Boolean = {
val serviceAuthHints = r.serviceHints.get(HttpBearerAuth.tagInstance).map(_ => Auth(Set(HttpBearerAuth.id.show)))
val serviceAuthHints =
r.serviceHints.get(HttpBearerAuth.tagInstance).flatMap(x => HttpBearerAuth.hints.get(Auth.tag))
for {
authSet <- r.endpointHints.get(Auth.tag) orElse serviceAuthHints
_ <- authSet.value.find(_.value == HttpBearerAuth.id.show)
Expand Down
156 changes: 77 additions & 79 deletions smithy4play/src/main/scala/de/innfactory/smithy4play/package.scala
Original file line number Diff line number Diff line change
@@ -1,104 +1,102 @@
package de.innfactory
package de.innfactory.smithy4play

import cats.data.{ EitherT, Kleisli }
import de.innfactory.smithy4play.client.{ SmithyPlayClientEndpointErrorResponse, SmithyPlayClientEndpointResponse }
import cats.data.{EitherT, Kleisli}
import de.innfactory.smithy4play.client.SmithyPlayClientEndpointErrorResponse
import org.slf4j
import play.api.Logger
import play.api.libs.json.{ JsValue, Json }
import play.api.mvc.{ Headers, RequestHeader }
import smithy4s.http.{ CaseInsensitive, HttpEndpoint }
import play.api.libs.json.{JsValue, Json, OFormat}
import play.api.mvc.{Headers, RequestHeader}
import smithy4s.http.{CaseInsensitive, HttpEndpoint}

import scala.annotation.{ compileTimeOnly, StaticAnnotation }
import scala.annotation.{StaticAnnotation, compileTimeOnly}
import scala.concurrent.Future
import scala.language.experimental.macros

package object smithy4play {

trait ContextRouteError extends StatusResult[ContextRouteError] {
def message: String
def toJson: JsValue
}
trait ContextRouteError extends StatusResult[ContextRouteError] {
def message: String
def toJson: JsValue
}

type ClientResponse[O] = Future[Either[SmithyPlayClientEndpointErrorResponse, SmithyPlayClientEndpointResponse[O]]]
type RunnableClientRequest[O] = Kleisli[ClientResponse, Option[Map[String, Seq[String]]], O]
type RouteResult[O] = EitherT[Future, ContextRouteError, O]
type ContextRoute[O] = Kleisli[RouteResult, RoutingContext, O]
type ClientResponse[O] = Future[
Either[SmithyPlayClientEndpointErrorResponse, SmithyPlayClientEndpointResponse[O]]
]
type RunnableClientRequest[O] = Kleisli[ClientResponse, Option[Map[String, Seq[String]]], O]
type RouteResult[O] = EitherT[Future, ContextRouteError, O]
type ContextRoute[O] = Kleisli[RouteResult, RoutingContext, O]

trait StatusResult[S <: StatusResult[S]] {
def status: Status
def addHeaders(headers: Map[String, String]): S
}
trait StatusResult[S <: StatusResult[S]] {
def status: Status
def addHeaders(headers: Map[String, String]): S
}

case class Status(headers: Map[String, String], statusCode: Int)
object Status {
implicit val format = Json.format[Status]
}
case class Status(headers: Map[String, String], statusCode: Int)
object Status {
implicit val format: OFormat[Status] = Json.format[Status]
}

case class EndpointResult(body: Option[Array[Byte]], status: Status) extends StatusResult[EndpointResult] {
override def addHeaders(headers: Map[String, String]): EndpointResult = this.copy(
status = status.copy(
headers = status.headers ++ headers
)
case class EndpointResult(body: Option[Array[Byte]], status: Status) extends StatusResult[EndpointResult] {
override def addHeaders(headers: Map[String, String]): EndpointResult = this.copy(
status = status.copy(
headers = status.headers ++ headers
)
}
)
}

private[smithy4play] case class Smithy4PlayError(
message: String,
status: Status,
additionalInformation: Option[String] = None
) extends ContextRouteError {
override def toJson: JsValue = Json.toJson(this)(Smithy4PlayError.format)
override def addHeaders(headers: Map[String, String]): Smithy4PlayError = this.copy(
status = status.copy(
headers = status.headers ++ headers
)
private[smithy4play] case class Smithy4PlayError(
message: String,
status: Status,
additionalInformation: Option[String] = None
) extends ContextRouteError {
override def toJson: JsValue = Json.toJson(this)(Smithy4PlayError.format)
override def addHeaders(headers: Map[String, String]): Smithy4PlayError = this.copy(
status = status.copy(
headers = status.headers ++ headers
)
}

object Smithy4PlayError {
implicit val format = Json.format[Smithy4PlayError]
}

private[smithy4play] val logger: slf4j.Logger = Logger("smithy4play").logger
)
}

private[smithy4play] def getHeaders(headers: Headers): Map[CaseInsensitive, Seq[String]] =
headers.headers.groupBy(_._1).map { case (k, v) =>
(CaseInsensitive(k), v.map(_._2))
}
object Smithy4PlayError {
implicit val format: OFormat[Smithy4PlayError] = Json.format[Smithy4PlayError]
}

private[smithy4play] def matchRequestPath(
x: RequestHeader,
ep: HttpEndpoint[_]
): Option[Map[String, String]] =
ep.matches(x.path.replaceFirst("/", "").split("/").filter(_.nonEmpty))
private[smithy4play] val logger: slf4j.Logger = Logger("smithy4play").logger

@compileTimeOnly(
"Macro failed to expand. \"Add: scalacOptions += \"-Ymacro-annotations\"\" to project settings"
)
class AutoRouting extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro AutoRoutingMacro.impl
private[smithy4play] def getHeaders(headers: Headers): Map[CaseInsensitive, Seq[String]] =
headers.headers.groupBy(_._1).map { case (k, v) =>
(CaseInsensitive(k), v.map(_._2))
}

private[smithy4play] trait Showable {
this: Product =>
override def toString: String = this.show
}
private[smithy4play] def matchRequestPath(
x: RequestHeader,
ep: HttpEndpoint[_]
): Option[Map[String, String]] =
ep.matches(x.path.replaceFirst("/", "").split("/").filter(_.nonEmpty))

@compileTimeOnly(
"Macro failed to expand. \"Add: scalacOptions += \"-Ymacro-annotations\"\" to project settings"
)
class AutoRouting extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro AutoRoutingMacro.impl
}

private[smithy4play] object Showable {
implicit class ShowableProduct(product: Product) {
def show: String = {
val className = product.productPrefix
val fieldNames = product.productElementNames.toList
val fieldValues = product.productIterator.toList
val fields = fieldNames.zip(fieldValues).map { case (name, value) =>
value match {
case subProduct: Product => s"$name = ${subProduct.show}"
case _ => s"$name = $value"
}
private[smithy4play] trait Showable {
this: Product =>
override def toString: String = this.show
}

private[smithy4play] object Showable {
implicit class ShowableProduct(product: Product) {
def show: String = {
val className = product.productPrefix
val fieldNames = product.productElementNames.toList
val fieldValues = product.productIterator.toList
val fields = fieldNames.zip(fieldValues).map { case (name, value) =>
value match {
case subProduct: Product => s"$name = ${subProduct.show}"
case _ => s"$name = $value"
}
fields.mkString(s"$className(", ", ", ")")
}
fields.mkString(s"$className(", ", ", ")")
}
}

}

0 comments on commit 8b61f9c

Please sign in to comment.