diff --git a/.github/workflows/main_test_release.yml b/.github/workflows/main_test_release.yml
index 3e005c57..1f5eff5d 100644
--- a/.github/workflows/main_test_release.yml
+++ b/.github/workflows/main_test_release.yml
@@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
mongodb-version: ['4.4', '5.0', '6.0', '7.0']
- java: [ '11', '17' ]
+ java: [ '11', '17', '21' ]
steps:
- uses: actions/checkout@v3.0.0
- name: Setup TimeZone
diff --git a/.github/workflows/other_test.yml b/.github/workflows/other_test.yml
index 5f0c0daf..167e228d 100644
--- a/.github/workflows/other_test.yml
+++ b/.github/workflows/other_test.yml
@@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
mongodb-version: ['4.4', '5.0', '6.0', '7.0']
- java: [ '11', '17' ]
+ java: [ '11', '17', '21' ]
steps:
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.Java }}
diff --git a/.github/workflows/release_and_changelog.yml b/.github/workflows/release_and_changelog.yml
index d588c905..0dd0c12c 100644
--- a/.github/workflows/release_and_changelog.yml
+++ b/.github/workflows/release_and_changelog.yml
@@ -28,9 +28,35 @@ jobs:
body: ${{ steps.changelog.outputs.changes }}
token: ${{ github.token }}
+ - name: Update versions file
+ run: |
+ echo "{\"mongocamp\": \"${{ github.ref_name }}\"}" > ./docs/versions.json;
+ git add ./docs/versions.json
+
- name: Commit CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }}'
- file_pattern: CHANGELOG.md
\ No newline at end of file
+ file_pattern: CHANGELOG.md
+
+ - name: Set up JDK
+ uses: coursier/setup-action@v1
+ with:
+ jvm: graalvm-java17:22.3.3
+ apps: sbt scala scalac
+
+ - name: Install pnpm
+ uses: pnpm/action-setup@v2.2.1
+ with:
+ version: 6.0.2
+
+ - name: Build and deploy Docu
+ env:
+ CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ GITHUB_USER: ${{ github.actor }}
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ git config --global user.email "ci@mongocamp.dev"
+ git config --global user.name "MongoCamp CI"
+ sh ./deploy_ghpages.sh
\ No newline at end of file
diff --git a/build.sbt b/build.sbt
index 1a427d36..6949d423 100644
--- a/build.sbt
+++ b/build.sbt
@@ -79,7 +79,7 @@ libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "4.11.0"
libraryDependencies += "org.xerial.snappy" % "snappy-java" % "1.1.10.5" % Provided
-libraryDependencies += "com.github.luben" % "zstd-jni" % "1.5.5-6" % Provided
+libraryDependencies += "com.github.luben" % "zstd-jni" % "1.5.5-10" % Provided
libraryDependencies += "org.apache.lucene" % "lucene-queryparser" % "9.8.0"
diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts
index 4d0a61ad..316659c9 100644
--- a/docs/.vitepress/config.ts
+++ b/docs/.vitepress/config.ts
@@ -1,7 +1,6 @@
import Unocss from 'unocss/vite'
import {defineConfig} from 'vitepress'
-import {version} from '../../package.json'
-import {SearchPlugin} from 'vitepress-plugin-search'
+import fs from 'fs'
export default defineConfig({
lang: 'en-US',
@@ -50,6 +49,8 @@ export default defineConfig({
})
function nav() {
+ var versionInfos = JSON.parse(fs.readFileSync('docs/versions.json', 'utf-8'))
+
return [
{
text: 'Documentation',
@@ -63,7 +64,7 @@ function nav() {
]
},
{
- text: version,
+ text: versionInfos.mongocamp,
items: [
{
text: 'Changelog',
diff --git a/docs/versions.json b/docs/versions.json
new file mode 100644
index 00000000..8a574c81
--- /dev/null
+++ b/docs/versions.json
@@ -0,0 +1 @@
+{"mongocamp": "2.6.6"}
diff --git a/package.json b/package.json
index 53995219..94e33661 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name" : "mongodb-driver",
"organization" : "dev.mongocamp",
- "version" : "2.6.6.snapshot",
+ "version" : "2.6.7.snapshot",
"author" : "info@mongocamp.dev",
"license" : "Apache-2.0",
"repository" : {
@@ -9,7 +9,7 @@
"url" : "git+https://github.com/MongoCamp/mongodb-driver.git"
},
"bugs" : {
- "url" : "https://github.com/MongoCamp/mongocamp-driver/issues"
+ "url" : "https://github.com/MongoCamp/mongodb-driver/issues"
},
"homepage" : "https://mongodb-driver.mongocamp.dev/",
"scripts" : {
diff --git a/project/plugins.sbt b/project/plugins.sbt
index 295e1036..858d37d1 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -1,8 +1,8 @@
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
-addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
+addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
-addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.7")
+addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
@@ -13,13 +13,13 @@ addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
addSbtPlugin("com.github.fedragon" % "sbt-todolist" % "0.7")
// Release
-addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.18")
+addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.1.1")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")
-addSbtPlugin("dev.quadstingray" %% "sbt-json" % "0.6.3")
+addSbtPlugin("dev.quadstingray" %% "sbt-json" % "0.6.5")
addDependencyTreePlugin
diff --git a/scalastyle-config.xml b/scalastyle-config.xml
index 9123d9d4..11b327cb 100644
--- a/scalastyle-config.xml
+++ b/scalastyle-config.xml
@@ -85,7 +85,7 @@
-
+
diff --git a/src/main/scala/dev/mongocamp/driver/mongodb/bson/BsonConverter.scala b/src/main/scala/dev/mongocamp/driver/mongodb/bson/BsonConverter.scala
index 6421e17d..93fc7f3d 100644
--- a/src/main/scala/dev/mongocamp/driver/mongodb/bson/BsonConverter.scala
+++ b/src/main/scala/dev/mongocamp/driver/mongodb/bson/BsonConverter.scala
@@ -8,6 +8,7 @@ import java.math.BigInteger
import java.time.{ LocalDate, LocalDateTime, ZoneId }
import java.util.Date
import scala.collection.mutable
+import scala.concurrent.duration.Duration
import scala.jdk.CollectionConverters._
import scala.util.matching.Regex
@@ -22,7 +23,7 @@ object BsonConverter {
def lastKeyFromRelation(key: String): String = key.substring(key.lastIndexOf(DocumentKeyDivider) + 1)
- def documentValueOption(document: Document, key: String): Option[Any] =
+ def documentValueOption(document: Document, key: String): Option[Any] = {
if (hasRelation(key)) {
val newKey = newKeyFromRelation(key)
val relation = relationKey(key)
@@ -36,13 +37,17 @@ object BsonConverter {
None
}
}
- else
+ else {
None
+ }
}
- else if (document.contains(key))
+ else if (document.contains(key)) {
Some(fromBson(document(key)))
- else
+ }
+ else {
None
+ }
+ }
def updateDocumentValue(document: Document, key: String, value: Any): Document = {
val doc = org.mongodb.scala.bson.collection.mutable.Document(document.toJson())
@@ -110,6 +115,7 @@ object BsonConverter {
case bytes: Array[Byte] => BsonBinary(bytes)
case r: Regex => BsonRegularExpression(r)
case d: Date => BsonDateTime(d)
+ case d: Duration => BsonString(d.toString)
case ld: LocalDate =>
BsonDateTime(Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant))
case ldt: LocalDateTime =>
diff --git a/src/test/scala/dev/mongocamp/driver/mongodb/bson/JodaConverterPlugin.scala b/src/test/scala/dev/mongocamp/driver/mongodb/bson/JodaConverterPlugin.scala
index 8740d2c3..8d435657 100644
--- a/src/test/scala/dev/mongocamp/driver/mongodb/bson/JodaConverterPlugin.scala
+++ b/src/test/scala/dev/mongocamp/driver/mongodb/bson/JodaConverterPlugin.scala
@@ -1,15 +1,18 @@
package dev.mongocamp.driver.mongodb.bson
import org.bson.BsonValue
-import org.joda.time.DateTime
-import org.mongodb.scala.bson.{BsonDateTime, BsonNull}
+import org.joda.time.{DateTime, Duration}
+import org.mongodb.scala.bson.{BsonDateTime, BsonNull, BsonString}
class JodaConverterPlugin extends AbstractConverterPlugin {
- override def customClassList: List[Class[_]] = List(classOf[DateTime])
+ override def customClassList: List[Class[_]] = List(classOf[DateTime], classOf[Duration])
override def toBson(value: Any): BsonValue =
value match {
- case dt: DateTime => BsonDateTime(dt.toDate)
+ case dt: DateTime =>
+ BsonDateTime(dt.toDate)
+ case dt: org.joda.time.Duration =>
+ BsonString(s"${dt.getMillis}ms")
case _ =>
BsonNull()
diff --git a/src/test/scala/dev/mongocamp/driver/mongodb/bson/JodaConverterPluginSpec.scala b/src/test/scala/dev/mongocamp/driver/mongodb/bson/JodaConverterPluginSpec.scala
new file mode 100644
index 00000000..99210833
--- /dev/null
+++ b/src/test/scala/dev/mongocamp/driver/mongodb/bson/JodaConverterPluginSpec.scala
@@ -0,0 +1,36 @@
+package dev.mongocamp.driver.mongodb.bson
+
+import org.joda.time.DateTime
+import org.specs2.mutable.Specification
+import org.specs2.specification.BeforeAfterAll
+
+import scala.concurrent.duration.Duration
+
+class JodaConverterPluginSpec extends Specification with BeforeAfterAll {
+
+ sequential
+
+ "JodaConverterPlugin" should {
+
+ "convert joda dates to bson dates" in {
+ val dateTime = new DateTime("2023-11-02")
+ val bsonDocument = BsonConverter.toBson(dateTime)
+ (bsonDocument.toString must be).equalTo("BsonDateTime{value=1698879600000}")
+ }
+
+ "convert joda duration to bson string" in {
+ val duration = org.joda.time.Duration.standardDays(1)
+ val bsonDocument = BsonConverter.toBson(duration)
+ (bsonDocument.toString must be).equalTo("BsonString{value='86400000ms'}")
+ (Duration("86400000ms").toMillis must be).equalTo(duration.getMillis)
+ }
+
+ }
+
+ override def beforeAll(): Unit = {
+ BsonConverter.converterPlugin = new JodaConverterPlugin()
+ }
+ override def afterAll(): Unit = {
+ BsonConverter.converterPlugin = new BaseConverterPlugin()
+ }
+}