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

Add sphere-mongo-3 and sphere-json-3 (the scala 3 version of similarly named modules) #651

Open
wants to merge 74 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
ff4171a
sphere-mongo-derivation-scala-3
peter-empen Feb 21, 2024
6aab3f9
sphere-mongo-core, sphere-util compiles with both Scala 2 and 3
benko-ct Feb 22, 2024
91424e0
some macro test code
benko-ct Feb 22, 2024
04a2d75
some macro test code2
benko-ct Feb 22, 2024
bbabb8a
some macro test code2
benko-ct Feb 22, 2024
77787a9
some macro test code2
benko-ct Feb 22, 2024
33049ff
start module and case-class derivation
peter-empen Feb 23, 2024
4cee24d
Autoderivation example with fake bson
benko-ct Feb 26, 2024
3a120ca
brush up specs
peter-empen Feb 29, 2024
c888f4f
add .bsp to .gitignore
peter-empen Feb 29, 2024
cf41666
scalafmt
peter-empen Feb 29, 2024
4da664c
fix SBT warnings on target
peter-empen Mar 1, 2024
a8845d1
Port the initial implementation from FakeBson to Actual MongoDB types
benko-ct Apr 19, 2024
396417a
Add MongoKey and MongoEmbedded implementations
benko-ct Apr 29, 2024
dbee359
Add MongoTypeHint and MongoTypeHintField
benko-ct May 17, 2024
02388ea
ENE-49 Fix infinite loop in derivation
programaker May 23, 2024
9298ec3
ENE-49 Add a case with `implicit` keyword
programaker May 23, 2024
8ced215
add DefaultValuesSpec
peter-empen May 23, 2024
eccd881
Merge branch 'ENE-49__fix-derivation-infinite-loop' into scala-3
programaker May 23, 2024
e4ccd28
Fix OptionMongoFormatSpec
benko-ct May 23, 2024
244dd51
Refactor AnnotationReader macro functions and Remove bad imports.
benko-ct May 23, 2024
cccf067
Move TypedMongoFormat instances to DefaultMongoFormats
benko-ct May 23, 2024
e19d164
ENE-49 Enums work
programaker May 23, 2024
363d3e7
Merge branch 'ENE-49__dev' into scala-3
programaker May 23, 2024
2f5d1eb
Support default values
benko-ct May 23, 2024
1eb13a2
ENE-49 Solve merge conflicts
programaker May 23, 2024
e2b478a
ENE-49 Spec for class with fields with default value
programaker May 23, 2024
aecda6e
Add DeriveMongoFormatSpec
benko-ct May 23, 2024
67943d7
brushing up some code
peter-empen May 24, 2024
ba48367
stat with MongoIgnore
peter-empen May 24, 2024
1b85335
ENE-49 Porting Json Lib - Initial version
ysedira May 24, 2024
8f2d38e
Fix tests
benko-ct May 24, 2024
991644c
toMongoValue with MongoIgnore
peter-empen May 24, 2024
722edac
Fix some Option/Null behaviour
benko-ct Jun 17, 2024
425bc8d
remove warnings
benko-ct Jun 17, 2024
e5dc7f4
Fix sumtype writer
benko-ct Jun 17, 2024
0796166
change implicits to given
benko-ct Jun 17, 2024
76e0073
remove forProduct spec because it was only testing the internal detai…
benko-ct Jun 17, 2024
62a6b76
Add deriveSingletonJSON
benko-ct Jun 18, 2024
0294477
sphere-json-core now compiles with Scala3
benko-ct Jul 1, 2024
7bf1515
Turn off indentation based syntax.
benko-ct Jul 19, 2024
f4311e6
Turn off indentation based syntax.
benko-ct Jul 19, 2024
f2cbf08
Move sphere-json-derivation-3 to sphere-json-core (just the main, not…
benko-ct Jul 20, 2024
185d1c7
Merge branch 'refs/heads/main' into scala-3
benko-ct Aug 15, 2024
7b84b3c
move mongo-derivation-3 to mongo-3, separating the MongoFormat implem…
benko-ct Nov 22, 2024
3a509a5
Port DefaultMongoFormats to mongo-3
benko-ct Nov 25, 2024
bd03551
Add BaseMoneyMongoFormatTest
benko-ct Nov 25, 2024
a8490a8
Remove "New anonymous class definition will be duplicated at each inl…
benko-ct Nov 25, 2024
5c8db69
Revert "Remove "New anonymous class definition will be duplicated at …
benko-ct Nov 25, 2024
52e5e05
Small refactor
benko-ct Nov 25, 2024
4eb3676
Small refactor
benko-ct Nov 25, 2024
830e497
Revert "Move sphere-json-derivation-3 to sphere-json-core (just the m…
benko-ct Dec 5, 2024
ab83fdd
[ENE-49] util-3 and json-3 pure Scala 3 modules
programaker Dec 5, 2024
964f12e
[ENE-49] Remove fmpp from json-3. Remove json-derivation-3 module
programaker Dec 6, 2024
d35e499
Merge pull request #632 from commercetools/scala-3__json-3
benko-ct Dec 9, 2024
43438a2
Add mongoTypeSwitch
benko-ct Jan 30, 2025
f9f0ef5
Add mongoTypeSwitch
benko-ct Jan 30, 2025
e2cf5eb
Fix JSON derivation (moving the actual derivation to FromJSON and ToJ…
benko-ct Feb 21, 2025
e0a00e6
Merge branch 'main' into scala-3
benko-ct Feb 21, 2025
868050b
merge compiler option switches
benko-ct Feb 21, 2025
c6bf620
Remove util-3 as util is compatible with both scala 2 and 3
benko-ct Feb 21, 2025
65573fa
Formatting
benko-ct Feb 21, 2025
d2bd471
Trying to make the pipeline work
benko-ct Feb 21, 2025
214003f
Trying to make the pipeline work
benko-ct Feb 21, 2025
1b46be7
Trying to make the pipeline work
benko-ct Feb 21, 2025
d290d98
Trying to make the pipeline work
benko-ct Feb 21, 2025
f1ff371
Trying to make the pipeline work
benko-ct Feb 21, 2025
eed2c79
Trying to make the pipeline work
benko-ct Feb 21, 2025
c553fc9
Trying to make the pipeline work
benko-ct Feb 21, 2025
40ab176
Trying to make the pipeline work
benko-ct Feb 21, 2025
d1f850d
Remove useless code
benko-ct Feb 21, 2025
7e7c87a
Trying different cross compilation settings
benko-ct Feb 21, 2025
c43a36e
Fix some package names/imports
benko-ct Feb 21, 2025
ac35627
Trying different cross compilation settings
benko-ct Feb 21, 2025
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
Prev Previous commit
Next Next commit
ENE-49 Fix infinite loop in derivation
programaker committed May 23, 2024
commit 02388ea9619d4ea754df8015c5566a9b0b55fc2a
Original file line number Diff line number Diff line change
@@ -27,9 +27,11 @@ private final class NativeMongoFormat[A <: SimpleMongoType] extends TypedMongoFo
def fromMongoValue(any: MongoType): A = any.asInstanceOf[A]
}

inline def deriveMongoFormat[A: TypedMongoFormat]: TypedMongoFormat[A] = summon
inline def deriveMongoFormat[A](using Mirror.Of[A]): TypedMongoFormat[A] = TypedMongoFormat.derived

object TypedMongoFormat:
inline def apply[A: TypedMongoFormat]: TypedMongoFormat[A] = summon

private val emptyFieldsSet: Vector[String] = Vector.empty
inline def readCaseClassMetaData[T]: CaseClassMetaData = ${ readCaseClassMetaDataImpl[T] }

@@ -41,7 +43,7 @@ object TypedMongoFormat:
private def readTraitMetaDataImpl[T: Type](using Quotes): Expr[TraitMetaData] =
AnnotationReader().readTraitMetaData[T]

inline given derive[A](using Mirror.Of[A]): TypedMongoFormat[A] = Derivation.derived
inline given derived[A](using Mirror.Of[A]): TypedMongoFormat[A] = Derivation.derived

given TypedMongoFormat[Int] = new NativeMongoFormat[Int]
given TypedMongoFormat[String] = new NativeMongoFormat[String]
Original file line number Diff line number Diff line change
@@ -6,8 +6,12 @@ import org.scalatest.matchers.must.Matchers
import org.scalatest.wordspec.AnyWordSpec

object SerializationTest:
// For semi-automatic derivarion
case class Something(a: Option[Int], b: Int = 2)

// For Automatic derivation with `derives`
case class Frunfles(a: Option[Int], b: Int = 2) derives TypedMongoFormat

object Color extends Enumeration:
val Blue, Red, Yellow = Value

@@ -24,23 +28,36 @@ class SerializationTest extends AnyWordSpec with Matchers:
dbo.put("a", Integer.valueOf(3))
dbo.put("b", Integer.valueOf(4))

// TODO what is this? :D
val med: TypedMongoFormat[Medium.type] = io.sphere.mongo.generic.deriveMongoFormat
// Using backwards-compatible `deriveMongoFormat`
given TypedMongoFormat[Something] = io.sphere.mongo.generic.deriveMongoFormat

val mongoFormat: TypedMongoFormat[Something] = io.sphere.mongo.generic.deriveMongoFormat
val something = mongoFormat.fromMongoValue(dbo)
val something = TypedMongoFormat[Something].fromMongoValue(dbo)
something mustBe Something(Some(3), 4)
}

"generate a format that serializes optional fields with value None as BSON objects without that field" in {
val testFormat: TypedMongoFormat[Something] = io.sphere.mongo.generic.deriveMongoFormat
// Using new Scala 3 `derived` special method
given TypedMongoFormat[Something] = TypedMongoFormat.derived

val something = Something(None, 1)
val serializedObject = testFormat.toMongoValue(something).asInstanceOf[BasicDBObject]
val serializedObject =
TypedMongoFormat[Something].toMongoValue(something).asInstanceOf[BasicDBObject]

serializedObject.keySet().contains("b") must be(true)
serializedObject.keySet().contains("a") must be(false)
TypedMongoFormat[Something].fromMongoValue(serializedObject) must be(something)
}

"generate a format that serializes optional fields with value None as BSON objects without that field (using derives)" in {
// Using an automatically-derived type via new Scala 3 `derives` directive
val frunfles = Frunfles(None, 1)

testFormat.fromMongoValue(serializedObject) must be(something)
val serializedObject =
TypedMongoFormat[Frunfles].toMongoValue(frunfles).asInstanceOf[BasicDBObject]

serializedObject.keySet().contains("b") must be(true)
serializedObject.keySet().contains("a") must be(false)
TypedMongoFormat[Frunfles].fromMongoValue(serializedObject) must be(frunfles)
}

// "generate a format that use default values" in {