Skip to content

Commit

Permalink
Remove refined module as it lacks Scala 3 support
Browse files Browse the repository at this point in the history
Support for `refined` was added to Scanamo with #182
in January 2018, but unfortunately the `refined` library itself has limited support for
Scala 3 (see fthomas/refined#932), and as seen in
#1804, the tests for Scanamo's `refined` code do not
compile under Scala 3.

Although, when Scanamo gained Scala 3 support with PR #1596 in November 2022, we initially
continued `refined` support by restricting it to release only Scala 2 modules, in order to
simplify Scanamo's build and reduce ongoing maintenance burden, I'm now removing Scanamo's
`refined` module.

If `refined` gains enough Scala 3 support to cross-compile against all versions of Scala
supported by Scanamo, I'd definitely be happy for the `refined` module to be reintroduced
to Scanamo.
  • Loading branch information
rtyley committed Aug 28, 2024
1 parent fbdc953 commit 0e6d7b6
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 183 deletions.
18 changes: 3 additions & 15 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ comment: off
flags: scalaz-zio
target: auto
threshold: 100
base: auto
refined:
flags: refined
target: auto
threshold: 100
base: auto
base: auto
patch:
default: off
scanamo:
Expand Down Expand Up @@ -81,11 +76,7 @@ comment: off
scalaz-zio:
flags: scalaz-zio
threshold: 100
base: auto
refined:
flags: refined
threshold: 100
base: auto
base: auto
flags:
alpakka:
paths:
Expand All @@ -101,10 +92,7 @@ comment: off
- java-time/
joda:
paths:
- joda/
refined:
paths:
- refined/
- joda/
scalaz:
paths:
- scalaz/
Expand Down
10 changes: 1 addition & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,13 @@ jobs:
dynamodbLocalTestCleanup
stopDynamodbLocal
- name: test without coverage
if: matrix.scala-version == '2.13.14'
if: matrix.scala-version == '2.13.14' || matrix.scala-version == '3.3.3'
run: >
sbt ++${{ matrix.scala-version }}
startDynamodbLocal
test
dynamodbLocalTestCleanup
stopDynamodbLocal
- name: test without coverage
if: matrix.scala-version == '3.3.3'
run: >
sbt ++${{ matrix.scala-version }}
startDynamodbLocal
scanamo/test catsEffect/test joda/test pekko/test zio/test
dynamodbLocalTestCleanup
stopDynamodbLocal
- name: cleanup
run: bash <(curl -s https://codecov.io/bash)
test_docs:
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is now redundant, as we have moved the release process to gha-scala-library-release-workflow. The new changelog can be found here: https://github.com/scanamo/scanamo/releases

## Version 1.0.0-M10

- https://github.com/scanamo/scanamo/pull/295 Add missing floatFormat and floatSetFormat to DynamoFormat (@shtukas)
Expand Down
40 changes: 9 additions & 31 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ val V = new {
val catsEffectVersion = "3.5.4"
}

val scala2xVersions = Seq(V.scala212, V.scala213)
val allCrossVersions = Seq(V.scala212, V.scala213, V.scala3)
ThisBuild / scalaVersion := V.scala3

val scalaTest = "org.scalatest" %% "scalatest" % "3.2.19" % Test
val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.18.0" % Test
Expand Down Expand Up @@ -76,7 +75,7 @@ lazy val scala2settings = Seq(
})
)

lazy val kindprojectorSettings = Seq(
lazy val kindProjectorSettings = Seq(
Compile / scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Seq("-Ykind-projector:underscores")
Expand All @@ -95,6 +94,7 @@ lazy val macroSettings = Seq(
val commonSettings = Seq(
startYear := Some(2019),
homepage := Some(url("https://www.scanamo.org/")),
crossScalaVersions := Seq(V.scala212, V.scala213, V.scala3),
Test / scalacOptions := {
val mainScalacOptions = scalacOptions.value
(if (CrossVersion.partialVersion(scalaVersion.value).contains((2, 12)))
Expand All @@ -105,15 +105,12 @@ val commonSettings = Seq(
Compile / console / scalacOptions := (Test / scalacOptions).value,
autoAPIMappings := true,
apiURL := Some(url("https://www.scanamo.org/latest/api/")),
dynamoDBLocalDownloadDir := file(".dynamodb-local"),
dynamoDBLocalPort := 8042,
Test / parallelExecution := false
)

lazy val root = (project in file("."))
.aggregate(scanamo, testkit, refined, catsEffect, joda, zio, pekko)
.aggregate(scanamo, testkit, catsEffect, joda, zio, pekko)
.settings(
commonSettings,
publish / skip := true,
releaseVersion := ReleaseVersion.fromAggregatedAssessedCompatibilityWithLatestRelease().value,
releaseCrossBuild := true, // true if you cross-build the project for multiple Scala versions
Expand All @@ -127,34 +124,20 @@ lazy val root = (project in file("."))
setNextVersion,
commitNextVersion
),
dynamoDBLocalDownloadDir := file(".dynamodb-local"),
dynamoDBLocalPort := 8042,
startDynamoDBLocal / aggregate := false,
dynamoDBLocalTestCleanup / aggregate := false,
stopDynamoDBLocal / aggregate := false
)

val awsDynamoDB = "software.amazon.awssdk" % "dynamodb" % "2.26.25"

lazy val refined = (project in file("refined"))
.settings(
commonSettings,
publishingSettings,
name := "scanamo-refined",
crossScalaVersions := scala2xVersions
)
.settings(
libraryDependencies ++= Seq(
"eu.timepit" %% "refined" % "0.11.1",
scalaTest
)
)
.dependsOn(scanamo)

lazy val scanamo = (project in file("scanamo"))
.settings(
commonSettings,
publishingSettings,
name := "scanamo",
crossScalaVersions := allCrossVersions
name := "scanamo"
)
.settings(scala2settings)
.settings(macroSettings)
Expand All @@ -176,7 +159,6 @@ lazy val scanamo = (project in file("scanamo"))
lazy val testkit = (project in file("testkit"))
.settings(
commonSettings,
crossScalaVersions := allCrossVersions,
publishingSettings,
name := "scanamo-testkit",
libraryDependencies ++= Seq(
Expand All @@ -189,7 +171,6 @@ lazy val catsEffect = (project in file("cats"))
.settings(
name := "scanamo-cats-effect",
commonSettings,
crossScalaVersions := allCrossVersions,
publishingSettings,
libraryDependencies ++= List(
awsDynamoDB,
Expand All @@ -204,14 +185,13 @@ lazy val catsEffect = (project in file("cats"))
Compile / doc / scalacOptions += "-no-link-warnings"
)
.settings(scala2settings)
.settings(kindprojectorSettings)
.settings(kindProjectorSettings)
.dependsOn(scanamo, testkit % "test->test")

lazy val zio = (project in file("zio"))
.settings(
name := "scanamo-zio",
commonSettings,
crossScalaVersions := allCrossVersions,
publishingSettings,
libraryDependencies ++= List(
awsDynamoDB,
Expand All @@ -232,7 +212,6 @@ lazy val zio = (project in file("zio"))
lazy val pekko = (project in file("pekko"))
.settings(
commonSettings,
crossScalaVersions := allCrossVersions,
publishingSettings,
name := "scanamo-pekko"
)
Expand All @@ -254,7 +233,6 @@ lazy val pekko = (project in file("pekko"))
lazy val joda = (project in file("joda"))
.settings(
commonSettings,
crossScalaVersions := allCrossVersions,
publishingSettings,
name := "scanamo-joda"
)
Expand All @@ -278,7 +256,7 @@ lazy val docs = project
)
)
.enablePlugins(MdocPlugin, DocusaurusPlugin)
.dependsOn(scanamo % "compile->test", refined % "compile")
.dependsOn(scanamo % "compile->test")

val publishingSettings = Seq(
organization := "org.scanamo",
Expand Down
53 changes: 0 additions & 53 deletions docs/dynamo-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,59 +79,6 @@ scanamo.exec {
}.toList
```

### Formats for Refined Types

Scanamo supports Scala refined types via the `scanamo-refined` module, helping you to define custom formats
for types built using the predicates provided by the [refined](https://github.com/fthomas/refined) project.
Refined types give an extra layer of type safety to our programs making the compilation fail when we try to
assign wrong values to them.

To use them in your project you will need to include the dependency in your project:

```
libraryDependencies += "org.scanamo" %% "scanamo-refined" % "x.y.z"
```

And then import the support for refined types and define your model:

```scala mdoc:silent:reset
import org.scanamo._
import eu.timepit.refined._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric._
import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType._

val client = LocalDynamoDB.syncClient()
val scanamo = Scanamo(client)

type PosInt = Int Refined Positive

case class Customer(age: PosInt)

LocalDynamoDB.createTable(client)("Customer")("age" -> N)
```

You just now use it like if the type `PosInt` was natively supported by `scanamo`:

```scala mdoc
import org.scanamo.refined._
import org.scanamo.generic.auto._

val customerTable = Table[Customer]("Customer")
scanamo.exec {
for {
_ <- customerTable.put(Customer(67))
results <- customerTable.scan()
} yield results
}.toList
```

```scala mdoc:invisible
LocalDynamoDB.deleteTable(client)("foo")
LocalDynamoDB.deleteTable(client)("Customer")
```

### Derived Formats

Scanamo uses [magnolia](https://magnolia.work/opensource/magnolia) and implicit derivation to automatically derive `DynamoFormat`s for case classes and sealed trait families. You may also see or hear sealed trait families referred to as Algebraic Data Types (ADTs) and co-products. Here is an example that could be used to support event sourcing (assuming a table with a partition key of `id` and sort key `seqNo`):
Expand Down
35 changes: 0 additions & 35 deletions refined/src/main/scala/org/scanamo/refined/package.scala

This file was deleted.

This file was deleted.

0 comments on commit 0e6d7b6

Please sign in to comment.