diff --git a/build.sbt b/build.sbt index e303acb..ec538c1 100644 --- a/build.sbt +++ b/build.sbt @@ -8,7 +8,8 @@ lazy val globalSettings = Seq( licenses += ("The Apache Software License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")), homepage := Some(url("https://github.com/gnieh/sohva")), version := "2.0.2-SNAPSHOT", - scalaVersion := "2.11.8", + scalaVersion := "2.12.0", + crossScalaVersions := Seq("2.12.0", "2.11.8"), libraryDependencies ++= globalDependencies, parallelExecution := false, fork in Test := true, @@ -27,8 +28,8 @@ lazy val scalariform = scalariformSettings ++ Seq( lazy val globalDependencies = Seq( "org.scalatest" %% "scalatest" % "3.0.0" % "test", - "com.typesafe.akka" %% "akka-http-spray-json-experimental" % "2.4.10", - "org.gnieh" %% "diffson" % "2.0.2", + "com.typesafe.akka" %% "akka-http-spray-json" % "10.0.0", + "org.gnieh" %% "diffson-spray-json" % "2.1.0", "io.spray" %% "spray-json" % "1.3.2", "org.slf4j" % "slf4j-api" % "1.7.21" ) @@ -37,11 +38,11 @@ lazy val publishSettings = Seq( publishMavenStyle := true, publishArtifact in Test := false, // The Nexus repo we're publishing to. - publishTo <<= version { (v: String) => + publishTo := (version { (v: String) => val nexus = "https://oss.sonatype.org/" if (v.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots") else Some("releases" at nexus + "service/local/staging/deploy/maven2") - }, + }).value, pomIncludeRepository := { x => false }, pomExtra := ( @@ -74,7 +75,7 @@ lazy val sohva = project.in(file(".")) .settings(globalSettings: _*) .settings(publishSettings: _*) .settings(osgiSettings: _*) - .settings(scalariformSettings: _*) + .settings(scalariform: _*) .settings ( name := "sohva", description := "Couchdb client library", @@ -99,4 +100,4 @@ lazy val json = project.in(file("sohva-json")) .settings(globalSettings: _*) .settings( libraryDependencies ++= globalDependencies, - libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-reflect" % _)) + libraryDependencies += scalaVersion("org.scala-lang" % "scala-reflect" % _).value) diff --git a/project/build.properties b/project/build.properties index 748703f..27e88aa 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.7 +sbt.version=0.13.13 diff --git a/project/plugins.sbt b/project/plugins.sbt index ce3534d..e26f3b4 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,6 +4,6 @@ addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.2.0") addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.1") -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.3.5") +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.0") addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.1.0") diff --git a/src/main/scala/gnieh/sohva/BasicSession.scala b/src/main/scala/gnieh/sohva/BasicSession.scala index 98867bd..8979c4f 100644 --- a/src/main/scala/gnieh/sohva/BasicSession.scala +++ b/src/main/scala/gnieh/sohva/BasicSession.scala @@ -20,8 +20,7 @@ import scala.concurrent.Future import akka.http.scaladsl.model._ import akka.http.scaladsl.model.headers.BasicHttpCredentials -/** - * An instance of a Couch session that allows the user to perform authenticated +/** An instance of a Couch session that allows the user to perform authenticated * operations using HTTP basic authentication. * * @author Lucas Satabin diff --git a/src/main/scala/gnieh/sohva/CList.scala b/src/main/scala/gnieh/sohva/CList.scala index 5a6f9cf..d3aa57f 100644 --- a/src/main/scala/gnieh/sohva/CList.scala +++ b/src/main/scala/gnieh/sohva/CList.scala @@ -22,8 +22,7 @@ import akka.stream.ActorMaterializer import akka.http.scaladsl.model._ import akka.http.scaladsl.unmarshalling._ -/** - * A list that can be queried for a given view. +/** A list that can be queried for a given view. * * @author Lucas Satabin */ diff --git a/src/main/scala/gnieh/sohva/ChangeStream.scala b/src/main/scala/gnieh/sohva/ChangeStream.scala index 670093f..9b08b8a 100644 --- a/src/main/scala/gnieh/sohva/ChangeStream.scala +++ b/src/main/scala/gnieh/sohva/ChangeStream.scala @@ -43,8 +43,7 @@ import scala.concurrent.duration.Duration import java.util.concurrent.atomic.AtomicLong -/** - * A stream that represents a connection to the `_changes` stream of a database. +/** A stream that represents a connection to the `_changes` stream of a database. * * @author Lucas Satabin */ @@ -81,8 +80,8 @@ class ChangeStream(database: Database) { limit.map(n => "limit" -> n.toString), since.map { case Left("now") => "since" -> "now" - case Left(s) => throw new SohvaException(f"Unsupported `since` value $s") - case Right(s) => "since" -> CompactPrinter(s) + case Left(s) => throw new SohvaException(f"Unsupported `since` value $s") + case Right(s) => "since" -> CompactPrinter(s) }, style.map(s => "style" -> s), view.map(v => "view" -> v)).flatten @@ -98,8 +97,7 @@ class ChangeStream(database: Database) { } - /** - * Returns a continuous stream representing the changes in the database. Each change produces an element in the stream. + /** Returns a continuous stream representing the changes in the database. Each change produces an element in the stream. * The returned stream can be cancelled using the kill switch returned by materializing it. * E.g. if you want to log the changes to the console and shut it down after a while, you can write * {{{ @@ -135,8 +133,8 @@ class ChangeStream(database: Database) { limit.map(n => "limit" -> n.toString), since.map { case Left("now") => "since" -> "now" - case Left(s) => throw new SohvaException(f"Unsupported `since` value $s") - case Right(s) => "since" -> CompactPrinter(s) + case Left(s) => throw new SohvaException(f"Unsupported `since` value $s") + case Right(s) => "since" -> CompactPrinter(s) }, style.map(s => "style" -> s), view.map(v => "view" -> v)).flatten diff --git a/src/main/scala/gnieh/sohva/Configuration.scala b/src/main/scala/gnieh/sohva/Configuration.scala index fcc19ed..677e67b 100644 --- a/src/main/scala/gnieh/sohva/Configuration.scala +++ b/src/main/scala/gnieh/sohva/Configuration.scala @@ -19,8 +19,7 @@ import scala.util.Properties import java.util.Date -/** - * The configuration object of a couchdb instance +/** The configuration object of a couchdb instance * * @author Lucas Satabin */ diff --git a/src/main/scala/gnieh/sohva/CouchClient.scala b/src/main/scala/gnieh/sohva/CouchClient.scala index fe315ae..e7ecda2 100644 --- a/src/main/scala/gnieh/sohva/CouchClient.scala +++ b/src/main/scala/gnieh/sohva/CouchClient.scala @@ -33,8 +33,7 @@ import akka.stream.{ import akka.http.scaladsl.Http import akka.http.scaladsl.model._ -/** - * A CouchDB instance. +/** A CouchDB instance. * Allows users to access the different databases and instance information. * This is the key class to start with when one wants to work with couchdb. * Through this one you will get access to the sessions and anonymous access diff --git a/src/main/scala/gnieh/sohva/CouchDB.scala b/src/main/scala/gnieh/sohva/CouchDB.scala index c485e1e..bbdf7e5 100644 --- a/src/main/scala/gnieh/sohva/CouchDB.scala +++ b/src/main/scala/gnieh/sohva/CouchDB.scala @@ -44,8 +44,7 @@ import akka.util.ByteString import spray.json._ -/** - * A CouchDB instance. +/** A CouchDB instance. * Allows users to access the different databases and information. * This is the key class to start with when one wants to work with couchdb. * Through this one you will get access to the databases. @@ -114,8 +113,7 @@ abstract class CouchDB { .viaMat(KillSwitches.single)(Keep.right) } - /** - * Returns the list of nodes known by this node and the clusters. + /** Returns the list of nodes known by this node and the clusters. * * @group CouchDB2 */ @@ -164,8 +162,7 @@ abstract class CouchDB { def _config(section: String): Future[Map[String, String]] = config(section) - /** - * Returns the configuration section identified by its name + /** Returns the configuration section identified by its name * (an empty map is returned if the section does not exist) */ def config(section: String): Future[Map[String, String]] = @@ -178,8 +175,7 @@ abstract class CouchDB { def _config(section: String, key: String): Future[Option[String]] = config(section, key) - /** - * Returns the configuration value + /** Returns the configuration value * Returns `None` if the value does not exist */ def config(section: String, key: String): Future[Option[String]] = @@ -188,8 +184,7 @@ abstract class CouchDB { f"Failed to fetch config for $section with key `$key' from $uri" ) yield section.get(key) - /** - * Saves the given key/value association in the specified section + /** Saves the given key/value association in the specified section * The section and/or the key is created if it does not exist */ def saveConfigValue(section: String, key: String, value: String): Future[Boolean] = @@ -252,7 +247,7 @@ abstract class CouchDB { private def handleOptionalCouchResponse(response: HttpResponse): Future[Option[JsValue]] = handleCouchResponse(response).map(Some(_)).recoverWith { case CouchException(404, _) => Future.successful(None) - case err => Future.failed(err) + case err => Future.failed(err) } @inline diff --git a/src/main/scala/gnieh/sohva/CouchException.scala b/src/main/scala/gnieh/sohva/CouchException.scala index 8d5a560..5072ebd 100644 --- a/src/main/scala/gnieh/sohva/CouchException.scala +++ b/src/main/scala/gnieh/sohva/CouchException.scala @@ -30,7 +30,7 @@ object CouchException { def unapply(exn: Throwable): Option[(Int, Option[ErrorResult])] = exn match { case exn: CouchException => Some(exn.status -> exn.detail) - case _ => None + case _ => None } } @@ -39,7 +39,7 @@ object ConflictException { def unapply(exn: Throwable): Option[Option[ErrorResult]] = exn match { case CouchException(409, detail) => Some(detail) - case _ => None + case _ => None } } diff --git a/src/main/scala/gnieh/sohva/Database.scala b/src/main/scala/gnieh/sohva/Database.scala index e8ee5d7..e9146e8 100644 --- a/src/main/scala/gnieh/sohva/Database.scala +++ b/src/main/scala/gnieh/sohva/Database.scala @@ -209,7 +209,10 @@ class Database private[sohva] ( for { res <- builtInView("_all_docs").query[String, Map[String, String], JsObject](keys = ids) withFailureMessage f"Failed to fetch document revisions by IDs $ids from $uri" - } yield res.rows.map { case Row(Some(id), _, value, _) => (id, value("rev")) } + } yield res.rows.flatMap { + case Row(Some(id), _, value, _) => Some(id -> value("rev")) + case Row(None, _, _, _) => None + } /** * Finds documents using the declarative mango query syntax. See [[sohva.mango]] for details. diff --git a/src/main/scala/gnieh/sohva/Design.scala b/src/main/scala/gnieh/sohva/Design.scala index 3b02984..5f062e2 100644 --- a/src/main/scala/gnieh/sohva/Design.scala +++ b/src/main/scala/gnieh/sohva/Design.scala @@ -21,8 +21,7 @@ import spray.json._ import akka.http.scaladsl.model._ -/** - * A design gives access to the different views. +/** A design gives access to the different views. * Use this class to get or create new views. * * @author Lucas Satabin @@ -37,8 +36,7 @@ class Design(val db: Database, protected[sohva] val uri = db.uri / "_design" / name.trim - /** - * Check if the design exists. + /** Check if the design exists. * * @return true if it does, false otherwise */ @@ -46,8 +44,7 @@ class Design(val db: Database, for (h <- db.couch.rawHttp(HttpRequest(HttpMethods.HEAD, uri = uri))) yield h.status == StatusCodes.OK - /** - * Create an empty design document if none exists. + /** Create an empty design document if none exists. * Raises an exception if the design already exists. * * @return the design document if created.. @@ -59,8 +56,7 @@ class Design(val db: Database, else db.saveDoc(DesignDoc("_design/" + name, language, Map(), None, Map(), Map(), Map(), Map(), Nil)) } yield cr - /** - * Returns the design document from the couchdb instance. + /** Returns the design document from the couchdb instance. * Returns `None` if the design document does not exist. */ def getDesignDocument: Future[Option[DesignDoc]] = @@ -73,8 +69,7 @@ class Design(val db: Database, def delete: Future[Boolean] = db.deleteDoc("_design/" + name.trim) - /** - * Creates or updates the view in this design + /** Creates or updates the view in this design * with the given name, map function and reduce function. * If the design does not exist yet, it is created. */ @@ -83,8 +78,7 @@ class Design(val db: Database, reduceFun: Option[String] = None): Future[Unit] = saveView(viewName, ViewDoc(mapFun, reduceFun)) - /** - * Creates or updates the view in this design with the given name. + /** Creates or updates the view in this design with the given name. * If the design does not exist yet, it is created. */ def saveView(viewName: String, view: ViewDoc): Future[Unit] = @@ -121,8 +115,7 @@ class Design(val db: Database, def view(viewName: String): View = new View(this.name, db, viewName) - /** - * Creates or update the show function in this design with the given name. + /** Creates or update the show function in this design with the given name. * If the design does not exist yet, it is created. */ def saveShow(showName: String, showFun: String): Future[Unit] = @@ -159,8 +152,7 @@ class Design(val db: Database, def show(showName: String): Show = new Show(this.name, db, showName) - /** - * Creates or update the update function in this design with the given name. + /** Creates or update the update function in this design with the given name. * If the design does not exist yet, it is created. */ def saveList(listName: String, listFun: String): Future[Unit] = @@ -197,8 +189,7 @@ class Design(val db: Database, def list(listName: String): CList = new CList(this.name, db, listName) - /** - * Creates or update the update function in this design with the given name. + /** Creates or update the update function in this design with the given name. * If the design does not exist yet, it is created. */ def saveUpdate(updateName: String, updateFun: String): Future[Unit] = @@ -235,8 +226,7 @@ class Design(val db: Database, def update(updateName: String): Update = new Update(this.name, db, updateName) - /** - * Creates or updates the document validation function. + /** Creates or updates the document validation function. * If the design does not exist yet, it is created. */ def saveValidateFunction(validateFun: String): Future[Unit] = @@ -270,8 +260,7 @@ class Design(val db: Database, case None => Future.failed(new SohvaException("Unable to delete validate function for unknown design: " + name)) } - /** - * Creates or updates a filter function. + /** Creates or updates a filter function. * If the design does not exist yet, it is created. */ def saveFilter(name: String, filterFun: String): Future[Unit] = @@ -306,8 +295,7 @@ class Design(val db: Database, Future.failed(new SohvaException("Unable to delete filter " + filterName + " for unknown design " + name)) } - /** - * Creates or updates the list of rewrite rules. + /** Creates or updates the list of rewrite rules. * If the design does not exist yet, it is created. */ def saveRewriteRules(rules: List[RewriteRule]): Future[Unit] = @@ -331,7 +319,7 @@ class Design(val db: Database, for (design <- getDesignDocument) yield design match { case Some(d) => d.rewrites - case None => Nil + case None => Nil } /** Requests compaction of this design. */ diff --git a/src/main/scala/gnieh/sohva/DocumentOps.scala b/src/main/scala/gnieh/sohva/DocumentOps.scala index 4789aa5..8506a7b 100644 --- a/src/main/scala/gnieh/sohva/DocumentOps.scala +++ b/src/main/scala/gnieh/sohva/DocumentOps.scala @@ -44,8 +44,7 @@ abstract class DocumentOps { for (raw <- optHttp(HttpRequest(uri = uri / id < if (r.nonEmpty) Some("rev" -> r) else None))).withFailureMessage(f"Failed to fetch document by ID $id and revision $revision")) yield raw.map(_.convertTo[T]) - /** - * Creates or updates the given object as a document into this database + /** Creates or updates the given object as a document into this database * The given object must have an `_id` and an optional `_rev` fields * to conform to the couchdb document structure. * The saved revision is returned. If something went wrong, an exception is raised @@ -103,7 +102,7 @@ abstract class DocumentOps { resolved = strategy(base, last, current) res <- resolved match { case Some(resolved) => resolver(credit - 1, docId, lastRev, resolved) - case None => Future.failed(exn) + case None => Future.failed(exn) } } yield res } withFailureMessage f"Unable to resolve document with ID $docId at revision $baseRev" @@ -123,8 +122,7 @@ abstract class DocumentOps { Future.failed(new SohvaException("Document $id could not be saved")) } - /** - * Deletes the document from the database. + /** Deletes the document from the database. * The document will only be deleted if the caller provided the last revision */ def deleteDoc[T: CouchFormat](doc: T): Future[Boolean] = { diff --git a/src/main/scala/gnieh/sohva/OAuthSession.scala b/src/main/scala/gnieh/sohva/OAuthSession.scala index dcb6021..6023d32 100644 --- a/src/main/scala/gnieh/sohva/OAuthSession.scala +++ b/src/main/scala/gnieh/sohva/OAuthSession.scala @@ -21,8 +21,7 @@ import scala.concurrent.Future import akka.http.scaladsl.model._ -/** - * An instance of a Couch session that allows the user to perform authenticated +/** An instance of a Couch session that allows the user to perform authenticated * operations using OAuth. * * @author Lucas Satabin diff --git a/src/main/scala/gnieh/sohva/Replicator.scala b/src/main/scala/gnieh/sohva/Replicator.scala index 7f5d7ca..c8a0336 100644 --- a/src/main/scala/gnieh/sohva/Replicator.scala +++ b/src/main/scala/gnieh/sohva/Replicator.scala @@ -21,8 +21,7 @@ import java.net.URL import scala.concurrent.Future -/** - * A replicator database that allows people to manage replications: +/** A replicator database that allows people to manage replications: * - start replication * - cancel or stop replications * - list current replications @@ -34,8 +33,7 @@ class Replicator(name: String, couch: CouchDB, credit: Int, strategy: Strategy) import SohvaProtocol._ - /** - * Starts a new replication from `source` to `target`. if a replication + /** Starts a new replication from `source` to `target`. if a replication * task already exists for the same source and target, the document is added * but the replication is not started again. The result only contains the identifier * of the actual replication task, not its state. @@ -43,8 +41,7 @@ class Replicator(name: String, couch: CouchDB, credit: Int, strategy: Strategy) def start(replication: Replication): Future[Replication] = saveDoc(replication) - /** - * Stops the replication identified by the given replication document id. + /** Stops the replication identified by the given replication document id. * if the identifier does not describe the document that started the replication, * it is deleted from the replicator database, but the replication task is not stopped. * It returns `true` only if the replication was actually stopped, `false` otherwise. @@ -67,29 +64,25 @@ class Replicator(name: String, couch: CouchDB, credit: Int, strategy: Strategy) } -/** - * A Reference to a database. +/** A Reference to a database. * * @author Lucas Satabin */ abstract class DbRef(val string: String) -/** - * A Reference to a local database identified by its name. +/** A Reference to a local database identified by its name. * * @author Lucas Satabin */ case class LocalDb(name: String) extends DbRef(name) -/** - * A Reference to a remote database identified by its url. +/** A Reference to a remote database identified by its url. * * @author Lucas Satabin */ case class RemoteDb(url: URL) extends DbRef(url.toString) -/** - * A replication document contains information about a particular replication +/** A replication document contains information about a particular replication * process (continuous or not, ...) * * @author Lucas Satabin diff --git a/src/main/scala/gnieh/sohva/SecurityDoc.scala b/src/main/scala/gnieh/sohva/SecurityDoc.scala index 5b4724b..3685338 100644 --- a/src/main/scala/gnieh/sohva/SecurityDoc.scala +++ b/src/main/scala/gnieh/sohva/SecurityDoc.scala @@ -15,8 +15,7 @@ */ package gnieh.sohva -/** - * A security document is a special document for couchdb. It has no `_id` or +/** A security document is a special document for couchdb. It has no `_id` or * `_rev` field. * * @author Lucas Satabin diff --git a/src/main/scala/gnieh/sohva/Session.scala b/src/main/scala/gnieh/sohva/Session.scala index 0465eb2..f257ad1 100644 --- a/src/main/scala/gnieh/sohva/Session.scala +++ b/src/main/scala/gnieh/sohva/Session.scala @@ -23,8 +23,7 @@ import spray.json._ import akka.http.scaladsl.model._ -/** - * Methods that must be implemented by a session. +/** Methods that must be implemented by a session. * * @author Lucas Satabin */ @@ -42,13 +41,13 @@ trait Session extends CouchDB { /** Indicates whether the current session is authenticated with the couch server */ def isAuthenticated: Future[Boolean] = userContext.map { case UserCtx(Some(name), _) => true - case _ => false + case _ => false } /** Indicates whether the current session gives the given role to the user */ def hasRole(role: String): Future[Boolean] = userContext.map { case UserCtx(_, roles) => roles.contains(role) - case _ => false + case _ => false } /** Indicates whether the current session is a server admin session */ @@ -72,8 +71,7 @@ case class AuthResult(ok: Boolean, userCtx: UserCtx, info: Option[AuthInfo]) /** The user context giving his name and roles */ case class UserCtx(name: Option[String], roles: List[String]) -/** - * Authentication information indicating the authentication database, +/** Authentication information indicating the authentication database, * the handler used and the authentication method */ case class AuthInfo(authentication_db: String, diff --git a/src/main/scala/gnieh/sohva/Show.scala b/src/main/scala/gnieh/sohva/Show.scala index f8dc84e..a76bbd3 100644 --- a/src/main/scala/gnieh/sohva/Show.scala +++ b/src/main/scala/gnieh/sohva/Show.scala @@ -20,8 +20,7 @@ import scala.concurrent.Future import akka.http.scaladsl.model._ import akka.http.scaladsl.unmarshalling._ -/** - * A show function that can be queried. +/** A show function that can be queried. * * @author Lucas Satabin */ @@ -41,8 +40,7 @@ class Show( for (h <- db.couch.rawHttp(HttpRequest(HttpMethods.HEAD, uri = uri))) yield h.status == StatusCodes.OK - /** - * Returns the result of querying the show function with the document with the given identifier + /** Returns the result of querying the show function with the document with the given identifier * or `None` for the `null` document. */ def query[T: FromEntityUnmarshaller](docId: Option[String] = None, format: Option[String] = None): Future[T] = diff --git a/src/main/scala/gnieh/sohva/SohvaProtocol.scala b/src/main/scala/gnieh/sohva/SohvaProtocol.scala index 9c5a8a3..6fc6776 100644 --- a/src/main/scala/gnieh/sohva/SohvaProtocol.scala +++ b/src/main/scala/gnieh/sohva/SohvaProtocol.scala @@ -128,15 +128,15 @@ trait SohvaProtocol extends DefaultJsonProtocol with MangoProtocol with CouchFor case JsObject(fields) => fields.get("ok") match { case Some(JsBoolean(_)) => value.convertTo[OkResult] - case None => value.convertTo[ErrorResult] - case _ => deserializationError(f"database result expected but got $value") + case None => value.convertTo[ErrorResult] + case _ => deserializationError(f"database result expected but got $value") } case _ => deserializationError(f"database result expected but got $value") } def write(result: DbResult): JsValue = result match { - case ok: OkResult => ok.toJson + case ok: OkResult => ok.toJson case error: ErrorResult => error.toJson } @@ -173,11 +173,11 @@ trait SohvaProtocol extends DefaultJsonProtocol with MangoProtocol with CouchFor "password" -> JsString(user.password)) val fields2 = user._rev match { case Some(r) => fields1 + ("_rev" -> JsString(r)) - case None => fields1 + case None => fields1 } val fields3 = user.oauth match { case Some(oauth) => fields2 + ("oauth" -> oauth.toJson) - case None => fields2 + case None => fields2 } JsObject(fields3) } @@ -223,8 +223,7 @@ trait SohvaProtocol extends DefaultJsonProtocol with MangoProtocol with CouchFor implicit val changesFormat = jsonFormat3(Changes) - /** - * (De)Serialize a database reference (remote or local). + /** (De)Serialize a database reference (remote or local). * * @author Lucas Satabin */ diff --git a/src/main/scala/gnieh/sohva/Update.scala b/src/main/scala/gnieh/sohva/Update.scala index dcef98e..6029093 100644 --- a/src/main/scala/gnieh/sohva/Update.scala +++ b/src/main/scala/gnieh/sohva/Update.scala @@ -24,8 +24,7 @@ import akka.http.scaladsl.marshalling._ import akka.http.scaladsl.unmarshalling._ import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport -/** - * An update handler that can be queried. +/** An update handler that can be queried. * * @author Lucas Satabin */ @@ -44,8 +43,7 @@ class Update(val design: String, val db: Database, val update: String) { for (h <- db.couch.rawHttp(HttpRequest(HttpMethods.HEAD, uri = uri))) yield h.status == StatusCodes.OK - /** - * Queries the update handler as a POST request. + /** Queries the update handler as a POST request. * `body` is sent as a json value. */ def query[Body: RootJsonWriter, Resp: FromEntityUnmarshaller]( @@ -56,7 +54,7 @@ class Update(val design: String, val db: Database, val update: String) { entity <- Marshal(body).to[RequestEntity] req = docId match { case Some(docId) => HttpRequest(HttpMethods.PUT, uri = uri / docId < HttpRequest(HttpMethods.POST, uri = uri < HttpRequest(HttpMethods.POST, uri = uri < JsString(field) + case Asc(field) => JsString(field) case Desc(field) => JsObject(Map(field -> JsString("desc"))) } @@ -38,13 +38,13 @@ trait MangoProtocol extends DefaultJsonProtocol { implicit object objectTypeFormat extends JsonFormat[ObjectType] { def read(json: JsValue): ObjectType = json match { - case JsString("null") => NullObject + case JsString("null") => NullObject case JsString("boolean") => BooleanObject - case JsString("number") => NumberObject - case JsString("string") => StringObject - case JsString("array") => ArrayObject - case JsString("object") => ObjectObject - case _ => deserializationError(f"object type object expected but got $json") + case JsString("number") => NumberObject + case JsString("string") => StringObject + case JsString("array") => ArrayObject + case JsString("object") => ObjectObject + case _ => deserializationError(f"object type object expected but got $json") } def write(tpe: ObjectType): JsString = JsString(tpe.value) @@ -100,34 +100,34 @@ trait MangoProtocol extends DefaultJsonProtocol { case JsObject(fields) if fields.size > 0 => fields.map(read).toVector match { case Vector(sel) => sel - case sels => And(sels) + case sels => And(sels) } case _ => Eq(json) } def write(selector: Selector): JsObject = selector match { - case Empty => JsObject() + case Empty => JsObject() case Field(name, sub) => JsObject(Map(name -> write(sub))) - case And(sub) => JsObject(Map("$and" -> JsArray(sub.map(write)))) - case Or(sub) => JsObject(Map("$or" -> JsArray(sub.map(write)))) - case Not(sub) => JsObject(Map("$not" -> write(sub))) - case Nor(sub) => JsObject(Map("$nor" -> JsArray(sub.map(write)))) - case All(values) => JsObject(Map("$all" -> JsArray(values))) - case ElemMatch(sub) => JsObject(Map("$elemMatch" -> write(sub))) - case Eq(value) => JsObject(Map("$eq" -> value)) - case Ne(value) => JsObject(Map("$ne" -> value)) - case Lt(value) => JsObject(Map("$lt" -> value)) - case Lte(value) => JsObject(Map("$lte" -> value)) - case Gt(value) => JsObject(Map("$gt" -> value)) - case Gte(value) => JsObject(Map("$gte" -> value)) - case Exists(e) => JsObject(Map("$exists" -> JsBoolean(e))) - case Type(tpe) => JsObject(Map("$type" -> JsString(tpe.value))) - case In(values) => JsObject(Map("$in" -> JsArray(values))) - case Nin(values) => JsObject(Map("$nin" -> JsArray(values))) - case Size(s) => JsObject(Map("$size" -> JsNumber(s))) - case Mod(div, rem) => JsObject(Map("$mod" -> JsArray(JsNumber(div), JsNumber(rem)))) - case Regex(re) => JsObject(Map("$regex" -> JsString(re))) + case And(sub) => JsObject(Map("$and" -> JsArray(sub.map(write)))) + case Or(sub) => JsObject(Map("$or" -> JsArray(sub.map(write)))) + case Not(sub) => JsObject(Map("$not" -> write(sub))) + case Nor(sub) => JsObject(Map("$nor" -> JsArray(sub.map(write)))) + case All(values) => JsObject(Map("$all" -> JsArray(values))) + case ElemMatch(sub) => JsObject(Map("$elemMatch" -> write(sub))) + case Eq(value) => JsObject(Map("$eq" -> value)) + case Ne(value) => JsObject(Map("$ne" -> value)) + case Lt(value) => JsObject(Map("$lt" -> value)) + case Lte(value) => JsObject(Map("$lte" -> value)) + case Gt(value) => JsObject(Map("$gt" -> value)) + case Gte(value) => JsObject(Map("$gte" -> value)) + case Exists(e) => JsObject(Map("$exists" -> JsBoolean(e))) + case Type(tpe) => JsObject(Map("$type" -> JsString(tpe.value))) + case In(values) => JsObject(Map("$in" -> JsArray(values))) + case Nin(values) => JsObject(Map("$nin" -> JsArray(values))) + case Size(s) => JsObject(Map("$size" -> JsNumber(s))) + case Mod(div, rem) => JsObject(Map("$mod" -> JsArray(JsNumber(div), JsNumber(rem)))) + case Regex(re) => JsObject(Map("$regex" -> JsString(re))) } } diff --git a/src/main/scala/gnieh/sohva/mango/package.scala b/src/main/scala/gnieh/sohva/mango/package.scala index c74a88e..c219529 100644 --- a/src/main/scala/gnieh/sohva/mango/package.scala +++ b/src/main/scala/gnieh/sohva/mango/package.scala @@ -18,8 +18,7 @@ package gnieh.sohva import spray.json._ -/** - * The [mango query server](http://docs.couchdb.org/en/2.0.0/api/database/find.html) was introduced in CouchDB 2.0. +/** The [mango query server](http://docs.couchdb.org/en/2.0.0/api/database/find.html) was introduced in CouchDB 2.0. * It allows for querying documents in a database with a declarative syntax and is easier to use that the classic CouchDB views. */ package object mango { diff --git a/src/main/scala/gnieh/sohva/mango/selectors.scala b/src/main/scala/gnieh/sohva/mango/selectors.scala index ad005d0..45772cb 100644 --- a/src/main/scala/gnieh/sohva/mango/selectors.scala +++ b/src/main/scala/gnieh/sohva/mango/selectors.scala @@ -24,24 +24,24 @@ sealed abstract class Selector { def &&(that: Selector): Selector = (this, that) match { case (And(subs1), And(subs2)) => And(subs1 ++ subs2) - case (And(subs), _) => And(subs :+ that) - case (_, And(subs)) => And(this +: subs) - case (_, _) => And(Vector(this, that)) + case (And(subs), _) => And(subs :+ that) + case (_, And(subs)) => And(this +: subs) + case (_, _) => And(Vector(this, that)) } def ||(that: Selector): Selector = (this, that) match { case (Or(subs1), Or(subs2)) => Or(subs1 ++ subs2) - case (Or(subs), _) => Or(subs :+ that) - case (_, Or(subs)) => Or(this +: subs) - case (_, _) => Or(Vector(this, that)) + case (Or(subs), _) => Or(subs :+ that) + case (_, Or(subs)) => Or(this +: subs) + case (_, _) => Or(Vector(this, that)) } def unary_! : Selector = this match { case Not(sub) => sub case Or(subs) => Nor(subs) - case _ => Not(this) + case _ => Not(this) } } @@ -90,13 +90,13 @@ case object ObjectObject extends ObjectType("object") object ObjectType { def apply(str: String): ObjectType = str match { - case "null" => NullObject + case "null" => NullObject case "boolean" => BooleanObject - case "number" => NumberObject - case "string" => StringObject - case "array" => ArrayObject - case "object" => ObjectObject - case _ => throw new SohvaException(f"Unknown type $str") + case "number" => NumberObject + case "string" => StringObject + case "array" => ArrayObject + case "object" => ObjectObject + case _ => throw new SohvaException(f"Unknown type $str") } } diff --git a/src/main/scala/gnieh/sohva/strategy/BarneyStinsonStrategy.scala b/src/main/scala/gnieh/sohva/strategy/BarneyStinsonStrategy.scala index 19eb873..9de29fc 100644 --- a/src/main/scala/gnieh/sohva/strategy/BarneyStinsonStrategy.scala +++ b/src/main/scala/gnieh/sohva/strategy/BarneyStinsonStrategy.scala @@ -18,8 +18,7 @@ package strategy import spray.json._ -/** - * This strategy applies a simple rule: ''New is always better'' +/** This strategy applies a simple rule: ''New is always better'' * Whenever a conflict occurs when trying to save a document in the database, * the newest document (the one the client wants to store) is taken and overrides * the previous revision. @@ -37,7 +36,7 @@ object BarneyStinsonStrategy extends Strategy { // remove the _rev field if present val clean = fields.filter { case ("_rev", _) => false - case _ => true + case _ => true } Some(JsObject(clean + ("_rev" -> lastDoc("_rev")))) case _ => @@ -49,7 +48,7 @@ object BarneyStinsonStrategy extends Strategy { // the document was deleted, drop the revision from the new document and retry Some(JsObject(currentDoc.asJsObject.fields.filter { case ("_rev", _) => false - case _ => true + case _ => true })) } } diff --git a/src/main/scala/gnieh/sohva/strategy/Strategy.scala b/src/main/scala/gnieh/sohva/strategy/Strategy.scala index 4123e29..7ab182f 100644 --- a/src/main/scala/gnieh/sohva/strategy/Strategy.scala +++ b/src/main/scala/gnieh/sohva/strategy/Strategy.scala @@ -18,8 +18,7 @@ package strategy import spray.json._ -/** - * A strategy indicates how update conflict are resolved. +/** A strategy indicates how update conflict are resolved. * It is used by the conflict resolver at each try and may be called * several times with the same document if the document changed while the * strategy was applied. @@ -28,8 +27,7 @@ import spray.json._ */ trait Strategy { - /** - * Applies the resolving strategy between the last known revision `baseDoc` + /** Applies the resolving strategy between the last known revision `baseDoc` * (or `None` if the document did not exist before to the client knowledge), * the last revision in the database `lastDoc` (or `None` if the document was deleted) * and the document the client wants to save `currentDoc`. diff --git a/src/main/scala/gnieh/sohva/strategy/StructuralMergeStrategy.scala b/src/main/scala/gnieh/sohva/strategy/StructuralMergeStrategy.scala index 26afd1c..1393a0f 100644 --- a/src/main/scala/gnieh/sohva/strategy/StructuralMergeStrategy.scala +++ b/src/main/scala/gnieh/sohva/strategy/StructuralMergeStrategy.scala @@ -23,8 +23,7 @@ import sprayJson._ import spray.json._ -/** - * This strategy applies a simple structural merge algorithm between variation from +/** This strategy applies a simple structural merge algorithm between variation from * a base document to the last one in the database and from the base to the current * revision of the document to merge * @@ -171,7 +170,7 @@ object StructuralMergeStrategy extends Strategy { // the document was deleted, simply remove the revision from the current document Some(JsObject(currentJson.asJsObject.fields.filter { case ("_rev", _) => false - case _ => true + case _ => true })) } @@ -200,7 +199,7 @@ object StructuralMergeStrategy extends Strategy { val parent = elems.dropRight(1) elems.last match { case int(idx) => Some(Pointer(parent: _*) -> idx.toInt) - case _ => None + case _ => None } case _ => None @@ -211,7 +210,7 @@ object StructuralMergeStrategy extends Strategy { def addedIn(ops: List[Operation], p: Pointer): Boolean = ops exists { case Add(path, _) => path == p - case _ => false + case _ => false } /** Indicates whether an operation exists in the list that modifies the pointer or one of its parents */ diff --git a/src/main/scala/gnieh/sohva/strategy/TedMosbyStrategy.scala b/src/main/scala/gnieh/sohva/strategy/TedMosbyStrategy.scala index 9e0aca4..1970f1b 100644 --- a/src/main/scala/gnieh/sohva/strategy/TedMosbyStrategy.scala +++ b/src/main/scala/gnieh/sohva/strategy/TedMosbyStrategy.scala @@ -18,8 +18,7 @@ package strategy import spray.json._ -/** - * This strategy is the anti-[[BarneyStinsonStrategy]] by definition as it applies +/** This strategy is the anti-[[BarneyStinsonStrategy]] by definition as it applies * a simple rule: ''Old is always better''. * Whenever a conflict occurs when trying to save a document in the database, * the oldest document (the one from the database) is kept.