Skip to content

Commit

Permalink
Migrate to Scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
dlindhol committed Jan 26, 2024
1 parent 424721c commit e48b745
Show file tree
Hide file tree
Showing 34 changed files with 107 additions and 107 deletions.
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
ThisBuild / organization := "io.latis-data"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / scalaVersion := "3.3.1"

val fs2DataVersion = "1.8.1"
val http4sVersion = "0.23.25"
val latisVersion = "ea2ab6c"
val latisHapiVersion = "e30933f"
val latisVersion = "4abcef6" //TODO: update when latis3's scala-3 branch is merged
val latisHapiVersion = "3e21c35" //TODO: update when latis3-hapi's scala-3 branch is merged

lazy val root = (project in file("."))
.settings(
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/latis/ops/ConvertHapiTypes.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package latis.ops

import cats.syntax.all._
import cats.syntax.all.*

import latis.data._
import latis.data.Data._
import latis.model._
import latis.data.*
import latis.data.Data.*
import latis.model.*
import latis.util.LatisException

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/latis/ops/ToHapiTime.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package latis.ops

import cats.implicits._
import cats.implicits.*

import latis.data.Sample
import latis.model._
import latis.model.*
import latis.time.Time
import latis.time.TimeFormat
import latis.util.LatisException
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/latis/service/hapi/AboutResponse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final case class AboutResponse(
object AboutResponse {

/** JSON encoder */
implicit val encoder: Encoder[AboutResponse] =
given encoder: Encoder[AboutResponse] =
Encoder.forProduct8(
"version",
"status",
Expand All @@ -48,4 +48,4 @@ object AboutResponse {
ar.contactId,
ar.citation
) }.mapJson(_.dropNullValues)
}
}
4 changes: 2 additions & 2 deletions src/main/scala/latis/service/hapi/AboutService.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package latis.service.hapi

import cats.effect.Concurrent
import io.circe.syntax._
import io.circe.syntax.*
import org.http4s.HttpRoutes
import org.http4s.circe._
import org.http4s.circe.*
import org.http4s.dsl.Http4sDsl

import latis.util.LatisConfig
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/latis/service/hapi/Bin.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package latis.service.hapi

import io.circe.Encoder
import io.circe.generic.semiauto._
import io.circe.generic.semiauto.*

/**
* Represents a parameter's bin.
Expand All @@ -25,16 +25,16 @@ final case class Bin(
object Bin {

/** JSON encoder */
implicit val encoder: Encoder[Bin] =
given encoder: Encoder[Bin] =
deriveEncoder[Bin].mapJsonObject { obj =>
obj.filter {
case ("centers", _) =>
// Keep "centers" regardless of its value if "ranges" is
// null or missing.
obj("ranges").map(_.isNull).getOrElse(true)
obj("ranges").forall(_.isNull)
case (_, v) =>
// Remove all other null fields.
!v.isNull
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/scala/latis/service/hapi/Capabilities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final case class Capabilities(
object Capabilities {

/** JSON encoder */
implicit val encoder: Encoder[Capabilities] =
given encoder: Encoder[Capabilities] =
Encoder.forProduct3("HAPI", "status", "outputFormats") { x =>
(x.version, x.status, x.formats)
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/latis/service/hapi/CapabilitiesService.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package latis.service.hapi

import cats.effect.Concurrent
import io.circe.syntax._
import io.circe.syntax.*
import org.http4s.HttpRoutes
import org.http4s.circe._
import org.http4s.circe.*
import org.http4s.dsl.Http4sDsl

/** Implements the `/capabilities` endpoint. */
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/latis/service/hapi/Catalog.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final case class Catalog(
object Catalog {

/** JSON encoder */
implicit val encoder: Encoder[Catalog] =
given encoder: Encoder[Catalog] =
Encoder.forProduct3("HAPI", "status", "catalog") { x =>
(x.version, x.status, x.catalog)
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/latis/service/hapi/CatalogService.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package latis.service.hapi

import cats.effect.Concurrent
import cats.implicits._
import io.circe.syntax._
import cats.implicits.*
import io.circe.syntax.*
import org.http4s.HttpRoutes
import org.http4s.circe._
import org.http4s.circe.*
import org.http4s.dsl.Http4sDsl

/**
Expand Down
14 changes: 7 additions & 7 deletions src/main/scala/latis/service/hapi/DataService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ package latis.service.hapi
import cats.data.EitherT
import cats.data.NonEmptyList
import cats.effect.Concurrent
import cats.implicits._
import cats.implicits.*
import fs2.Stream
import io.circe.syntax._
import io.circe.syntax.*
import org.http4s.{Status => _, _}
import org.http4s.circe._
import org.http4s.circe.*
import org.http4s.dsl.Http4sDsl
import org.http4s.headers.`Content-Type`
import org.log4s._
import org.log4s.*

/** Implements the `/data` endpoint. */
class DataService[F[_]: Concurrent](
alg: DataAlgebra[F] with InfoAlgebra[F]
) extends Http4sDsl[F] {
import Format._
import Include._
import QueryDecoders._
import Format.*
import Include.*
import QueryDecoders.*

private[this] val logger = getLogger

Expand Down
14 changes: 7 additions & 7 deletions src/main/scala/latis/service/hapi/DataType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import io.circe.Json
sealed trait DataType

/** String data */
final case object HString extends DataType
case object HString extends DataType

/** Double data, 8-byte IEEE 754 format */
final case object HDouble extends DataType
case object HDouble extends DataType

/** Integer data, 4-byte signed, little-endian */
final case object HInteger extends DataType
case object HInteger extends DataType

/** Time string data, restricted ISO 8601 */
final case object HIsoTime extends DataType
case object HIsoTime extends DataType

object DataType {

/** JSON encoder */
implicit val encoder: Encoder[DataType] =
given encoder: Encoder[DataType] =
Encoder.instance {
case HString => Json.fromString("string")
case HDouble => Json.fromString("double")
case HInteger => Json.fromString("integer")
case HIsoTime => Json.fromString("isotime")
}
}
}
2 changes: 1 addition & 1 deletion src/main/scala/latis/service/hapi/Dataset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object Dataset {
Dataset(id, id)

/** JSON encoder */
implicit val encoder: Encoder[Dataset] =
given encoder: Encoder[Dataset] =
Encoder.forProduct2("id", "title") { x =>
(x.id, x.title)
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/scala/latis/service/hapi/Format.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package latis.service.hapi

import cats.implicits._
import cats.implicits.*
import org.http4s.ParseFailure
import org.http4s.QueryParamDecoder
import org.http4s.QueryParameterValue
import org.http4s.dsl.io._
import org.http4s.dsl.io.*

/** Wrapper for `format` parameter. */
sealed trait Format

object Format {
final case object Csv extends Format
final case object Binary extends Format
final case object Json extends Format
case object Csv extends Format
case object Binary extends Format
case object Json extends Format

implicit val formatDecoder: QueryParamDecoder[Format] =
given formatDecoder: QueryParamDecoder[Format] =
new QueryParamDecoder[Format] {
override def decode(qpv: QueryParameterValue) = qpv.value match {
case "csv" => Csv.validNel
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/latis/service/hapi/HapiError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object HapiError {
HapiError(HapiService.version, status)

/** JSON encoder */
implicit val encoder: Encoder[HapiError] =
given encoder: Encoder[HapiError] =
Encoder.forProduct2("HAPI", "status") { x =>
(x.version, x.status)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/latis/service/hapi/HapiInterpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package latis.service.hapi
import cats.Applicative
import cats.data.EitherT
import cats.data.NonEmptyList
import cats.implicits._
import cats.implicits.*
import fs2.Stream
import io.circe.JsonObject

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/latis/service/hapi/HapiService.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package latis.service.hapi

import cats.effect.IO
import cats.implicits._
import cats.implicits.*
import org.http4s.HttpRoutes

import latis.catalog.Catalog
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/latis/service/hapi/Include.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package latis.service.hapi

import cats.implicits._
import cats.implicits.*
import org.http4s.ParseFailure
import org.http4s.QueryParamDecoder
import org.http4s.QueryParameterValue
import org.http4s.dsl.io._
import org.http4s.dsl.io.*

/** Wrapper for `include` parameter. */
final case class Include(header: Boolean) extends AnyVal

object Include {

implicit val includeDecoder: QueryParamDecoder[Include] =
given includeDecoder: QueryParamDecoder[Include] =
new QueryParamDecoder[Include] {
override def decode(qpv: QueryParameterValue) = qpv.value match {
case "header" => Include(true).validNel
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/latis/service/hapi/InfoResponse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package latis.service.hapi

import io.circe.Encoder
import io.circe.Json
import io.circe.syntax._
import io.circe.syntax.*

/**
* Represents a response from the `info` service.
Expand All @@ -24,7 +24,7 @@ object InfoResponse {
*
* Note that we are flattening out the `metadata` field.
*/
implicit val encoder: Encoder[InfoResponse] =
given encoder: Encoder[InfoResponse] =
new Encoder[InfoResponse] {
override def apply(x: InfoResponse): Json =
Encoder[Metadata].apply(x.metadata).deepMerge(
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/latis/service/hapi/InfoService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package latis.service.hapi

import cats.data.EitherT
import cats.effect.Concurrent
import cats.implicits._
import io.circe.syntax._
import cats.implicits.*
import io.circe.syntax.*
import org.http4s.HttpRoutes
import org.http4s.circe._
import org.http4s.circe.*
import org.http4s.dsl.Http4sDsl
import org.log4s._
import org.log4s.*

/** Implements the `/info` endpoint. */
class InfoService[F[_]: Concurrent](alg: InfoAlgebra[F]) extends Http4sDsl[F] {
import QueryDecoders._
import QueryDecoders.*

private[this] val logger = getLogger

Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/latis/service/hapi/LandingPageService.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package latis.service.hapi

import cats.Monad
import cats.syntax.all._
import cats.syntax.all.*
import org.http4s.HttpRoutes
import org.http4s.dsl.Http4sDsl
import org.http4s.scalatags._
import org.http4s.scalatags.*
import scalatags.Text
import scalatags.Text.all._
import scalatags.Text.all.*

/** Implements the HAPI landing page. */
class LandingPageService[F[_]: Monad](alg: CatalogAlgebra[F]) extends Http4sDsl[F] {
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/latis/service/hapi/Latis3Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.collection.immutable.ListMap
import cats.data.EitherT
import cats.data.NonEmptyList
import cats.effect.IO
import cats.implicits._
import cats.implicits.*
import fs2.Stream
import fs2.data.json
import fs2.data.json.circe.tokenizerForEncoder
Expand All @@ -31,10 +31,10 @@ import latis.output.BinaryEncoder
import latis.output.CsvEncoder
import latis.output.JsonEncoder
import latis.time.{Time => LTime}
import latis.util.HapiUtils._
import latis.util.HapiUtils.*
import latis.util.Identifier
import latis.util.Identifier.IdentifierStringContext
import latis.util.dap2.parser.ast._
import latis.util.Identifier.*
import latis.util.dap2.parser.ast.*
import latis.util.hapi.DataCodec

class Latis3Interpreter(catalog: Catalog) extends HapiInterpreter[IO] {
Expand Down Expand Up @@ -67,7 +67,7 @@ class Latis3Interpreter(catalog: Catalog) extends HapiInterpreter[IO] {
// This would indicate that the parameter wasn't found, so we
// should return an error.
missing = params.flatMap(_.find(! hasVariable(dataset, _)))
_ <- EitherT.fromOption[IO](missing.map(UnknownParam), ()).swap
_ <- EitherT.fromOption[IO](missing.map(UnknownParam.apply), ()).swap
// Get the metadata.
metadata <- EitherT.fromEither[IO](getDatasetMetadata(dataset))
} yield params.map { ps =>
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/latis/service/hapi/Metadata.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package latis.service.hapi

import cats.data.NonEmptyList
import io.circe.Encoder
import io.circe.generic.semiauto._
import io.circe.generic.semiauto.*

/**
* Represents metadata for HAPI datasets.
Expand Down Expand Up @@ -44,7 +44,7 @@ object Metadata {
*
* This encoder will drop parameters that are None.
*/
implicit val encoder: Encoder[Metadata] =
given encoder: Encoder[Metadata] =
deriveEncoder[Metadata].mapJsonObject {
_.filter {
case (_, v) => !v.isNull
Expand Down
Loading

0 comments on commit e48b745

Please sign in to comment.