Skip to content

Commit

Permalink
Get rid of simulacrum
Browse files Browse the repository at this point in the history
  • Loading branch information
danslapman committed Feb 3, 2024
1 parent eaa029e commit d5910a8
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 636 deletions.
13 changes: 0 additions & 13 deletions backend/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ val dataAccess = (project in file("dataAccess"))
libraryDependencies ++= Dependencies.alleycats ++ Dependencies.cats ++ Dependencies.zio ++ Dependencies.catsTagless ++ Dependencies.mouse ++ Seq(
"com.beachape" %% "enumeratum" % "1.7.0",
"org.mongodb.scala" %% "mongo-scala-driver" % Versions.mongoScalaDriver,
"org.typelevel" %% "simulacrum-scalafix-annotations" % Versions.simulacrum,
"com.chuusai" %% "shapeless" % "2.3.3",
"org.julienrf" %% "enum-labels" % "3.1",
"tf.tofu" %% "derevo-core" % Versions.derevo,
Expand Down Expand Up @@ -119,10 +118,6 @@ lazy val `mockingbird-api` = (project in file("mockingbird-api"))
addCommandAlias(
"lintAll",
"scalafixAll; scalafmtAll"
),
addCommandAlias(
"simulacrum",
"scalafixEnable;scalafix AddSerializable;scalafix AddImplicitNotFound;scalafix TypeClassSupport;"
)
)

Expand Down Expand Up @@ -160,10 +155,6 @@ lazy val `mockingbird-native` = (project in file("mockingbird-native"))
addCommandAlias(
"lintAll",
"scalafixAll; scalafmtAll"
),
addCommandAlias(
"simulacrum",
"scalafixEnable;scalafix AddSerializable;scalafix AddImplicitNotFound;scalafix TypeClassSupport;"
)
)

Expand Down Expand Up @@ -214,10 +205,6 @@ val examples = (project in file("examples"))
addCommandAlias(
"lintAll",
"scalafixAll; scalafmtAll"
),
addCommandAlias(
"simulacrum",
"scalafixEnable;scalafix AddSerializable;scalafix AddImplicitNotFound;scalafix TypeClassSupport;"
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import scala.annotation.implicitNotFound
import scala.util.Try

import org.mongodb.scala.bson.*
import simulacrum.typeclass

@implicitNotFound("Could not find an instance of BsonDecoder for ${T}")
@typeclass
trait BsonDecoder[T] extends Serializable {
def fromBson(value: BsonValue): Try[T]

Expand All @@ -19,6 +17,8 @@ trait BsonDecoder[T] extends Serializable {
}

object BsonDecoder {
@inline def apply[T](implicit instance: BsonDecoder[T]): BsonDecoder[T] = instance

def ofDocument[T](f: BsonDocument => Try[T]): BsonDecoder[T] =
(value: BsonValue) => Try(value.asDocument()).flatMap(f)

Expand All @@ -33,44 +33,4 @@ object BsonDecoder {
bv => throw DeserializationError(s"Can't decode $bv")
)
)

/* ======================================================================== */
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/* ======================================================================== */

/**
* Summon an instance of [[BsonDecoder]] for `T`.
*/
@inline def apply[T](implicit instance: BsonDecoder[T]): BsonDecoder[T] = instance

object ops {
implicit def toAllBsonDecoderOps[T](target: T)(implicit tc: BsonDecoder[T]): AllOps[T] {
type TypeClassType = BsonDecoder[T]
} = new AllOps[T] {
type TypeClassType = BsonDecoder[T]
val self: T = target
val typeClassInstance: TypeClassType = tc
}
}
trait Ops[T] extends Serializable {
type TypeClassType <: BsonDecoder[T]
def self: T
val typeClassInstance: TypeClassType
}
trait AllOps[T] extends Ops[T]
trait ToBsonDecoderOps extends Serializable {
implicit def toBsonDecoderOps[T](target: T)(implicit tc: BsonDecoder[T]): Ops[T] {
type TypeClassType = BsonDecoder[T]
} = new Ops[T] {
type TypeClassType = BsonDecoder[T]
val self: T = target
val typeClassInstance: TypeClassType = tc
}
}
object nonInheritedOps extends ToBsonDecoderOps

/* ======================================================================== */
/* END OF SIMULACRUM-MANAGED CODE */
/* ======================================================================== */

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,21 @@ package ru.tinkoff.tcb.bson
import scala.annotation.implicitNotFound

import org.mongodb.scala.bson.BsonValue
import simulacrum.op
import simulacrum.typeclass

@implicitNotFound("Could not find an instance of BsonEncoder for ${T}")
@typeclass
trait BsonEncoder[T] extends Serializable {
@op("bson") def toBson(value: T): BsonValue
def toBson(value: T): BsonValue

def beforeWrite[U](f: U => T): BsonEncoder[U] =
(u: U) => toBson(f(u))
}

object BsonEncoder {
@inline def apply[T](implicit instance: BsonEncoder[T]): BsonEncoder[T] = instance

def constant[T](bv: BsonValue): BsonEncoder[T] =
(_: T) => bv

/* ======================================================================== */
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/* ======================================================================== */

/**
* Summon an instance of [[BsonEncoder]] for `T`.
*/
@inline def apply[T](implicit instance: BsonEncoder[T]): BsonEncoder[T] = instance

object ops {
implicit def toAllBsonEncoderOps[T](target: T)(implicit tc: BsonEncoder[T]): AllOps[T] {
type TypeClassType = BsonEncoder[T]
Expand All @@ -37,26 +27,13 @@ object BsonEncoder {
val typeClassInstance: TypeClassType = tc
}
}

trait Ops[T] extends Serializable {
type TypeClassType <: BsonEncoder[T]
def self: T
val typeClassInstance: TypeClassType
def bson: BsonValue = typeClassInstance.toBson(self)
}
trait AllOps[T] extends Ops[T]
trait ToBsonEncoderOps extends Serializable {
implicit def toBsonEncoderOps[T](target: T)(implicit tc: BsonEncoder[T]): Ops[T] {
type TypeClassType = BsonEncoder[T]
} = new Ops[T] {
type TypeClassType = BsonEncoder[T]
val self: T = target
val typeClassInstance: TypeClassType = tc
}
}
object nonInheritedOps extends ToBsonEncoderOps

/* ======================================================================== */
/* END OF SIMULACRUM-MANAGED CODE */
/* ======================================================================== */

trait AllOps[T] extends Ops[T]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package ru.tinkoff.tcb.bson
import scala.annotation.implicitNotFound
import scala.util.Try

import simulacrum.typeclass

@implicitNotFound("Could not find an instance of BsonKeyDecoder for ${T}")
@typeclass
trait BsonKeyDecoder[T] extends Serializable {
def decode(value: String): Try[T]

Expand All @@ -15,43 +12,5 @@ trait BsonKeyDecoder[T] extends Serializable {
}

object BsonKeyDecoder {
/* ======================================================================== */
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/* ======================================================================== */

/**
* Summon an instance of [[BsonKeyDecoder]] for `T`.
*/
@inline def apply[T](implicit instance: BsonKeyDecoder[T]): BsonKeyDecoder[T] = instance

object ops {
implicit def toAllBsonKeyDecoderOps[T](target: T)(implicit tc: BsonKeyDecoder[T]): AllOps[T] {
type TypeClassType = BsonKeyDecoder[T]
} = new AllOps[T] {
type TypeClassType = BsonKeyDecoder[T]
val self: T = target
val typeClassInstance: TypeClassType = tc
}
}
trait Ops[T] extends Serializable {
type TypeClassType <: BsonKeyDecoder[T]
def self: T
val typeClassInstance: TypeClassType
}
trait AllOps[T] extends Ops[T]
trait ToBsonKeyDecoderOps extends Serializable {
implicit def toBsonKeyDecoderOps[T](target: T)(implicit tc: BsonKeyDecoder[T]): Ops[T] {
type TypeClassType = BsonKeyDecoder[T]
} = new Ops[T] {
type TypeClassType = BsonKeyDecoder[T]
val self: T = target
val typeClassInstance: TypeClassType = tc
}
}
object nonInheritedOps extends ToBsonKeyDecoderOps

/* ======================================================================== */
/* END OF SIMULACRUM-MANAGED CODE */
/* ======================================================================== */

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package ru.tinkoff.tcb.bson

import scala.annotation.implicitNotFound

import simulacrum.typeclass

@implicitNotFound("Could not find an instance of BsonKeyEncoder for ${T}")
@typeclass
trait BsonKeyEncoder[T] extends Serializable {
def encode(t: T): String

Expand All @@ -14,44 +11,5 @@ trait BsonKeyEncoder[T] extends Serializable {
}

object BsonKeyEncoder {
/* ======================================================================== */
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/* ======================================================================== */

/**
* Summon an instance of [[BsonKeyEncoder]] for `T`.
*/
@inline def apply[T](implicit instance: BsonKeyEncoder[T]): BsonKeyEncoder[T] = instance

object ops {
implicit def toAllBsonKeyEncoderOps[T](target: T)(implicit tc: BsonKeyEncoder[T]): AllOps[T] {
type TypeClassType = BsonKeyEncoder[T]
} = new AllOps[T] {
type TypeClassType = BsonKeyEncoder[T]
val self: T = target
val typeClassInstance: TypeClassType = tc
}
}
trait Ops[T] extends Serializable {
type TypeClassType <: BsonKeyEncoder[T]
def self: T
val typeClassInstance: TypeClassType
def encode: String = typeClassInstance.encode(self)
}
trait AllOps[T] extends Ops[T]
trait ToBsonKeyEncoderOps extends Serializable {
implicit def toBsonKeyEncoderOps[T](target: T)(implicit tc: BsonKeyEncoder[T]): Ops[T] {
type TypeClassType = BsonKeyEncoder[T]
} = new Ops[T] {
type TypeClassType = BsonKeyEncoder[T]
val self: T = target
val typeClassInstance: TypeClassType = tc
}
}
object nonInheritedOps extends ToBsonKeyEncoderOps

/* ======================================================================== */
/* END OF SIMULACRUM-MANAGED CODE */
/* ======================================================================== */

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import enumeratum.EnumEntry
import enumeratum.values.StringEnumEntry
import io.circe.Json
import magnolia1.*
import simulacrum.typeclass

@implicitNotFound("Could not find an instance of Fields for ${T}")
@typeclass
trait Fields[T] extends Serializable {
def fields: List[String]
override def toString: String = fields.mkString(", ")
}
object Fields {
@inline def apply[T](implicit instance: Fields[T]): Fields[T] = instance

def mk[T](fs: List[String]): Fields[T] = new Fields[T] {
override def fields: List[String] = fs
}
Expand Down Expand Up @@ -49,44 +49,4 @@ object Fields {
def split[T](sealedTrait: SealedTrait[Typeclass, T]): Typeclass[T] = mk(Nil)

implicit def genFields[T]: Typeclass[T] = macro Magnolia.gen[T]

/* ======================================================================== */
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/* ======================================================================== */

/**
* Summon an instance of [[Fields]] for `T`.
*/
@inline def apply[T](implicit instance: Fields[T]): Fields[T] = instance

object ops {
implicit def toAllFieldsOps[T](target: T)(implicit tc: Fields[T]): AllOps[T] {
type TypeClassType = Fields[T]
} = new AllOps[T] {
type TypeClassType = Fields[T]
val self: T = target
val typeClassInstance: TypeClassType = tc
}
}
trait Ops[T] extends Serializable {
type TypeClassType <: Fields[T]
def self: T
val typeClassInstance: TypeClassType
}
trait AllOps[T] extends Ops[T]
trait ToFieldsOps extends Serializable {
implicit def toFieldsOps[T](target: T)(implicit tc: Fields[T]): Ops[T] {
type TypeClassType = Fields[T]
} = new Ops[T] {
type TypeClassType = Fields[T]
val self: T = target
val typeClassInstance: TypeClassType = tc
}
}
object nonInheritedOps extends ToFieldsOps

/* ======================================================================== */
/* END OF SIMULACRUM-MANAGED CODE */
/* ======================================================================== */

}
Loading

0 comments on commit d5910a8

Please sign in to comment.