Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try turning teleproto into a wrapper around chimney internal logic #338

Draft
wants to merge 48 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9e84459
Add Chimney dependency with a goal of turning teleproto into a wrappe…
urmaul Apr 18, 2024
8873b71
Comment out compileClassMapping
urmaul Apr 18, 2024
337e359
Try deriving Transformer
urmaul Apr 18, 2024
8bcf6d0
trait Writer extends Transformer
urmaul Apr 26, 2024
3a879dd
Delete covariance from Writer
urmaul May 3, 2024
5d2c0c5
Add many printlns
urmaul May 3, 2024
7868dc3
Catch the error
urmaul May 6, 2024
3c4938c
Revert "Add many printlns"
urmaul May 6, 2024
273562f
Relete covariance from Reader
urmaul May 8, 2024
ac0544e
Merge branch 'master' into delete_covariance
urmaul May 8, 2024
f8f106f
Delete migration
urmaul May 8, 2024
74942e5
Bump version
urmaul May 8, 2024
e2e3ab8
Merge remote-tracking branch 'origin/delete_covariance' into chimney_…
urmaul May 10, 2024
aa78885
uncomment generation
urmaul May 10, 2024
44c5334
fix test
urmaul May 10, 2024
c1ec2bb
Another fix
urmaul May 10, 2024
cb75c94
Merge remote-tracking branch 'origin/delete_migration' into chimney_w…
urmaul May 10, 2024
780e2d8
Inject import
urmaul May 10, 2024
49a38a8
Derive enum readers explicitly
urmaul May 17, 2024
86b11ad
Use own marcos only for enums
urmaul May 17, 2024
9a1e95f
Adjust MiMa filters
urmaul May 17, 2024
51519bd
Merge remote-tracking branch 'origin/delete_migration' into chimney_w…
urmaul May 17, 2024
8aa960c
Adjust MiMa filters
urmaul May 17, 2024
c820ba0
Remove commented out code
urmaul May 17, 2024
89676c7
Reader extends PartialTransformer
urmaul May 17, 2024
9c2c48b
add exclusion
urmaul May 31, 2024
a8d1408
Add Reader.fromPartialTransformer
urmaul May 31, 2024
24b9beb
Bump chimney to 1.0.0
urmaul May 31, 2024
466286e
Merge branch 'master' into chimney_wrapper
urmaul Jun 14, 2024
fcefcd0
Add some chimney conversions that dont help
urmaul Jun 14, 2024
d15bc3a
Restore ReaderImpl
urmaul Jun 21, 2024
1ef576b
Try turning teleproto into a wrapper around chimney internal logic
urmaul Jun 28, 2024
cebae1c
It compiles and tests pass
urmaul Jul 12, 2024
cff1e34
It compiles again
urmaul Jul 26, 2024
5e3b33b
Small cleanup
urmaul Jul 26, 2024
19af3c3
fix OneOfProtocolBuffersTest
urmaul Aug 23, 2024
c2f647f
Manual implementation for enum writers
urmaul Aug 23, 2024
4316e24
Tests somehow pass
urmaul Sep 6, 2024
8db6378
Protobuf enum writer works
urmaul Oct 4, 2024
603ac89
Exclude DirectMissingMethodProblem on WriterImpl.writer_impl
urmaul Oct 18, 2024
fc9b3a5
Cleanup HierarchicalProtocolBuffersTest
urmaul Oct 18, 2024
873edae
Fix infinite loop in implicit resolution
urmaul Oct 18, 2024
bec3f77
Cleanups
urmaul Oct 18, 2024
c38c79e
Cleanups
urmaul Oct 18, 2024
4ee9a26
More cleanup
urmaul Oct 18, 2024
f45b156
clenup
urmaul Oct 18, 2024
978d6d2
cleanup reader
urmaul Oct 18, 2024
ff4fa2c
Add dummy ReaderDerivation
urmaul Oct 18, 2024
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
32 changes: 28 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ lazy val `teleproto` = project
.settings(Project.inConfig(Test)(sbtprotoc.ProtocPlugin.protobufConfigSettings): _*)
.settings(
name := "teleproto",
version := "2.3.0",
version := "3.0.0",
versionScheme := Some("early-semver"),
libraryDependencies ++= Seq(
library.scalaPB % "protobuf;compile",
Expand All @@ -24,7 +24,9 @@ lazy val `teleproto` = project
library.scalaTestPlusCheck % Test,
library.scalaCheck % Test,
library.scalaCollectionCompat,
"org.scala-lang" % "scala-reflect" % (ThisBuild / scalaVersion).value
"org.scala-lang" % "scala-reflect" % (ThisBuild / scalaVersion).value,
"io.scalaland" %% "chimney" % "1.4.0",
"io.scalaland" %% "chimney-protobufs" % "1.4.0"
)
)

Expand Down Expand Up @@ -103,7 +105,7 @@ lazy val scalacOptions_2_13 = Seq(
"8",
"-encoding",
"UTF-8",
"-Xfatal-warnings",
// "-Xfatal-warnings", // TODO: restore
"-Xlint",
"-Ywarn-dead-code",
"-Ymacro-annotations"
Expand Down Expand Up @@ -157,7 +159,29 @@ lazy val mimaSettings = Seq(
mimaPreviousArtifacts := Set("io.moia" %% "teleproto" % "2.0.0"),
mimaBinaryIssueFilters ++= Seq(
// Method was added in 2.1.0
ProblemFilters.exclude[ReversedMissingMethodProblem]("io.moia.protos.teleproto.PbResult.toEither")
ProblemFilters.exclude[ReversedMissingMethodProblem]("io.moia.protos.teleproto.PbResult.toEither"),
// Classes were removed in 3.0.0
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.Migration"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.Migration$"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.MigrationImpl"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.MigrationImpl$Automatically"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.MigrationImpl$Automatically$"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.MigrationImpl$ParamMigration"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.MigrationImpl$Required"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.MigrationImpl$Required$"),
// Chimney migration stuff
ProblemFilters.exclude[DirectMissingMethodProblem]("io.moia.protos.teleproto.Reader.transform"),
ProblemFilters.exclude[DirectMissingMethodProblem]("io.moia.protos.teleproto.Writer.transform"),
ProblemFilters.exclude[DirectMissingMethodProblem]("io.moia.protos.teleproto.WriterImpl.writer_impl"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.WriterImpl$Compatible"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.WriterImpl$Compatible$"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.WriterImpl$ForwardCompatible"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.WriterImpl$ForwardCompatible$"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.WriterImpl$Matching"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.WriterImpl$MatchingParam"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.WriterImpl$SkippedDefaultParam$"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.WriterImpl$TransformParam"),
ProblemFilters.exclude[MissingClassProblem]("io.moia.protos.teleproto.WriterImpl$TransformParam$"),
)
)

Expand Down
91 changes: 91 additions & 0 deletions src/main/scala/io/moia/protos/teleproto/BaseTransformers.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package io.moia.protos.teleproto

import com.google.protobuf.timestamp.Timestamp
import io.moia.protos.teleproto.Writer.instance
import io.scalaland.chimney.Transformer
import com.google.protobuf.duration.{Duration => PBDuration}

import java.time.{Instant, LocalTime}
import java.util.UUID
import scala.collection.immutable.TreeMap
import scala.concurrent.duration.{Deadline, Duration}

object BaseTransformers {
/* Type Writers */

/** Writes a big decimal as string.
*/
implicit object BigDecimalWriter extends Transformer[BigDecimal, String] {
def transform(model: BigDecimal): String = model.toString
}

/** Writes a local time as ISO string.
*/
implicit object LocalTimeWriter extends Transformer[LocalTime, String] {
def transform(model: LocalTime): String = model.toString
}

/** Writes an instant into timestamp.
*/
implicit object InstantWriter extends Transformer[Instant, Timestamp] {
def transform(instant: Instant): Timestamp =
Timestamp(instant.getEpochSecond, instant.getNano)
}

/** Writes a Scala duration into ScalaPB duration.
*/
implicit object DurationWriter extends Transformer[Duration, PBDuration] {
def transform(duration: Duration): PBDuration =
PBDuration(duration.toSeconds, (duration.toNanos % 1000000000).toInt)
}

/** Writes a UUID as string.
*/
implicit object UUIDWriter extends Transformer[UUID, String] {
def transform(uuid: UUID): String = uuid.toString
}

/** Writes a Scala deadline into a ScalaPB Timestamp as fixed point in time.
*
* The decoding of this value is side-effect free but has a problem with divergent system clocks!
*
* Depending on the use case either this (based on fixed point in time) or the following writer (based on the time left) makes sense.
*/
object FixedPointDeadlineWriter extends Transformer[Deadline, Timestamp] {
def transform(deadline: Deadline): Timestamp = {
val absoluteDeadline = Instant.now.plusNanos(deadline.timeLeft.toNanos)
Timestamp(absoluteDeadline.getEpochSecond, absoluteDeadline.getNano)
}
}

/** Writes a Scala deadline into a ScalaPB int as time left duration.
*
* The decoding of this value is not side-effect free since it depends on the clock! Time between encoding and decoding does not count.
*
* Depending on the use case either this (based on time left) or the following writer (based on fixed point in time) makes sense.
*/
object TimeLeftDeadlineWriter extends Transformer[Deadline, PBDuration] {
def transform(deadline: Deadline): PBDuration = {
val timeLeft = deadline.timeLeft
val nanoAdjustment = timeLeft.toNanos % 1000000000L
PBDuration(timeLeft.toSeconds, nanoAdjustment.toInt)
}
}

/** Transforms a Scala map into a corresponding map with Protobuf types if writers exists between key and value types.
*/
implicit def mapWriter[MK, MV, PK, PV](implicit
keyWriter: Writer[MK, PK],
valueWriter: Writer[MV, PV]
): Writer[Map[MK, MV], Map[PK, PV]] = instance { model =>
for ((key, value) <- model) yield (keyWriter.write(key), valueWriter.write(value))
}

implicit def treeMapWriter[MK, MV, PK, PV](implicit
keyWriter: Writer[MK, PK],
valueWriter: Writer[MV, PV],
ordering: Ordering[PK]
): Writer[TreeMap[MK, MV], Map[PK, PV]] = instance { model =>
for ((key, value) <- model) yield (keyWriter.write(key), valueWriter.write(value))
}
}
42 changes: 0 additions & 42 deletions src/main/scala/io/moia/protos/teleproto/Migration.scala

This file was deleted.

Loading