Skip to content
Permalink
Browse files

Partial fix for #19 (#75)

* - migrate cmd

* - add contramap to Show, reformat implicitNotFound msg

* - RESPParamWrite reformat implicitNotFound msg, reorg instances classes

* - LowPriorityShowInstances -> ShowInstances and make sealed an package private

* - ops revert to using traits for init order

* - Read: modify implicitNotFound msg, replaced zip (unused and unneeded) with orElse (a bit more useful), combinators leverage Read constructors

* - echo and ping now accept any A: Show, also require NonNullBulkString ==> A evidence

* - reworded implicitNotFound msg, use widenLeft where appropriate

* more fixes

* - remove unneeded lazy vals in build.sbt for cross build components
- add comment on why we shadow scala.js plugin

* - toShowSyntax -> toShowOps

* - address codacy issues

* fixed compilation issue w/ scalatest 3.0.6

* wip geo

* Ignoring metals+bloom directories

* refactor Read instances names and grouping

* Fixed benchmarks compilation issues

* remove explicit evidence when not needed

* mostly code formatting

* more formatting

* refactor all RESP ADTs

* widen renamed to coerce where appropriate, more use of context bounds

* shuffling things around

* more cleanup, wip 2.11 broken

* more tests

* fixing 2.11 stack overflow in tests

* formatting

* more cleanup

* BaseSpec in core + must => should

* no implicit macro

* adding transation watch/unwatch

* cluster protocol commands

* testing more refined types

* completed tests on laserdisc-defined refined types

* polishing up

* removed manual refinements via refined API

* removed unuseful RESPBuilder and made Arr a wrapper on List[RESP] instead of Vector[RESP]

* no Show syntax, let Bulk handle Show

* renamed Extra to Ext(ended) and added a few tests

* roundtrip not round-trip

* nodes, finally

* bye bye 2.11

* minor README fix

* more ClusterP testing

* add cluster nodes test

* cleaning up tests

* fixed Host's RFC1123 hostname regex for JS

* cluster cleanup

* cluster cleanup - removed unnecessary parenthesis

* more on geo protocol

* completed geo protocol + tests

* wip on hash and key protocols

* removed last bit of 2.11/2.12 dichotomy

* minor cosmetics around geo protocol spec

* more hash tests

* added glob pattern generator + test and completed hash protocol spec

* wip key protocol

* still wip key protocol testing

* key protocol still missing SORT combinations

* added list protocol tests

* bump scalacheck to 1.14.0
  • Loading branch information...
sirocchj committed Aug 10, 2019
1 parent 45902bc commit d530ae7d5fbb83b77ae7d6918ba812f2fee06104
Showing with 6,450 additions and 3,052 deletions.
  1. +10 −1 .gitignore
  2. +1 −1 .scalafmt.conf
  3. +0 −1 .travis.yml
  4. +7 −9 README.md
  5. +4 −7 benchmarks/core/src/main/scala/laserdisc/protocol/ProtocolBench.scala
  6. +24 −24 benchmarks/core/src/main/scala/laserdisc/protocol/RESPBench.scala
  7. +3 −2 benchmarks/core/src/main/scala/laserdisc/protocol/RESPParamWriteBench.scala
  8. +2 −1 benchmarks/core/src/main/scala/laserdisc/protocol/UTF8EncodingBench.scala
  9. +35 −57 build.sbt
  10. +2 −3 circe/src/main/scala/laserdisc/interop/circe.scala
  11. +12 −14 circe/src/test/scala/laserdisc/interop/CirceSpec.scala
  12. +3 −3 cli/src/main/scala/laserdisc/cli/CLI.scala
  13. +24 −0 core/src/main/boilerplate/BListExtP.scala.template
  14. +0 −34 core/src/main/boilerplate/BListPExtra.scala.template
  15. +21 −0 core/src/main/boilerplate/GeoExtP.scala.template
  16. +5 −5 core/src/main/boilerplate/{HashPExtra.scala.template → HashExtP.scala.template}
  17. +1 −1 core/src/main/boilerplate/{HyperLogLogPExtra.scala.template → HyperLogLogExtP.scala.template}
  18. +11 −1 core/src/main/boilerplate/{KeyPExtra.scala.template → KeyExtP.scala.template}
  19. +14 −0 core/src/main/boilerplate/ListExtP.scala.template
  20. +0 −16 core/src/main/boilerplate/ListPExtra.scala.template
  21. +6 −15 core/src/main/boilerplate/{SetPExtra.scala.template → SetExtP.scala.template}
  22. +6 −7 core/src/main/boilerplate/{SortedSetPExtra.scala.template → SortedSetExtP.scala.template}
  23. +2 −5 core/src/main/boilerplate/{StringPExtra.scala.template → StringExtP.scala.template}
  24. +0 −20 core/src/main/scala-2.11/laserdisc/protocol.scala
  25. +209 −0 core/src/main/scala/laserdisc/laserdisc.scala
  26. +0 −136 core/src/main/scala/laserdisc/package.scala
  27. +10 −22 core/src/main/scala/laserdisc/protocol/BListP.scala
  28. +6 −13 core/src/main/scala/laserdisc/protocol/BitVectorSyntax.scala
  29. +313 −0 core/src/main/scala/laserdisc/protocol/ClusterP.scala
  30. +8 −14 core/src/main/scala/laserdisc/protocol/ConnectionP.scala
  31. +4 −4 core/src/main/scala/laserdisc/protocol/EitherSyntax.scala
  32. +417 −0 core/src/main/scala/laserdisc/protocol/GeoP.scala
  33. +26 −44 core/src/main/scala/laserdisc/protocol/HashP.scala
  34. +5 −7 core/src/main/scala/laserdisc/protocol/HyperLogLogP.scala
  35. +149 −114 core/src/main/scala/laserdisc/protocol/KeyP.scala
  36. +1 −1 core/src/main/scala/laserdisc/protocol/LenientStringCodec.scala
  37. +27 −38 core/src/main/scala/laserdisc/protocol/ListP.scala
  38. +17 −14 core/src/main/scala/laserdisc/protocol/Protocol.scala
  39. +1 −1 core/src/main/scala/laserdisc/protocol/PublishP.scala
  40. +209 −392 core/src/main/scala/laserdisc/protocol/RESP.scala
  41. +28 −42 core/src/main/scala/laserdisc/protocol/RESPFrame.scala
  42. +19 −18 core/src/main/scala/laserdisc/protocol/RESPParamWrite.scala
  43. +22 −24 core/src/main/scala/laserdisc/protocol/RESPRead.scala
  44. +160 −207 core/src/main/scala/laserdisc/protocol/Read.scala
  45. +73 −88 core/src/main/scala/laserdisc/protocol/ServerP.scala
  46. +28 −55 core/src/main/scala/laserdisc/protocol/SetP.scala
  47. +18 −7 core/src/main/scala/laserdisc/protocol/Show.scala
  48. +101 −167 core/src/main/scala/laserdisc/protocol/SortedSetP.scala
  49. +42 −80 core/src/main/scala/laserdisc/protocol/StringP.scala
  50. +10 −0 core/src/main/scala/laserdisc/protocol/TransactionP.scala
  51. +22 −16 core/src/main/scala/laserdisc/syntax.scala
  52. +18 −1 core/src/main/scala/laserdisc/types.scala
  53. +103 −0 core/src/test/boilerplate/BListExtPSpec.scala.template
  54. +85 −0 core/src/test/boilerplate/GeoExtPSpec.scala.template
  55. +51 −0 core/src/test/boilerplate/HashExtPSpec.scala.template
  56. +47 −0 core/src/test/boilerplate/HyperLogLogExtPSpec.scala.template
  57. +105 −0 core/src/test/boilerplate/KeyExtPSpec.scala.template
  58. +34 −0 core/src/test/boilerplate/ListExtPSpec.scala.template
  59. +0 −253 core/src/test/scala-2.11/laserdisc/HashPSpec.scala
  60. +0 −253 core/src/test/scala-2.12/laserdisc/HashPSpec.scala
  61. +0 −145 core/src/test/scala/laserdisc/BListPSpec.scala
  62. +148 −0 core/src/test/scala/laserdisc/BaseSpec.scala
  63. +0 −126 core/src/test/scala/laserdisc/ConnectionPSpec.scala
  64. +0 −61 core/src/test/scala/laserdisc/HyperLogLogPSpec.scala
  65. +778 −0 core/src/test/scala/laserdisc/RefinedTypesSpec.scala
  66. +96 −0 core/src/test/scala/laserdisc/protocol/BListPSpec.scala
  67. +421 −0 core/src/test/scala/laserdisc/protocol/ClusterPSpec.scala
  68. +96 −0 core/src/test/scala/laserdisc/protocol/ConnectionPSpec.scala
  69. +857 −0 core/src/test/scala/laserdisc/protocol/GeoPSpec.scala
  70. +277 −0 core/src/test/scala/laserdisc/protocol/HashPSpec.scala
  71. +44 −0 core/src/test/scala/laserdisc/protocol/HyperLogLogPSpec.scala
  72. +457 −0 core/src/test/scala/laserdisc/protocol/KeyPSpec.scala
  73. +188 −0 core/src/test/scala/laserdisc/protocol/ListPSpec.scala
  74. +94 −89 core/src/test/scala/laserdisc/protocol/RESPCodecsSpec.scala
  75. +164 −0 core/src/test/scala/laserdisc/protocol/RESPFrameArrSpec.scala
  76. +0 −154 core/src/test/scala/laserdisc/protocol/RESPFrameArraySpec.scala
  77. +105 −87 core/src/test/scala/laserdisc/protocol/RESPFrameBulkStringSpec.scala
  78. +101 −91 core/src/test/scala/laserdisc/protocol/RESPFrameMixedSpec.scala
  79. +28 −25 core/src/test/scala/laserdisc/protocol/RESPFunctionsSpec.scala
  80. +21 −0 core/src/test/scala/laserdisc/types.scala
  81. +0 −21 fs2/src/main/scala-2.11/laserdisc/fs2/fs2.scala
  82. +4 −3 fs2/src/main/scala/laserdisc/fs2/ProtocolHandler.scala
  83. +1 −2 fs2/src/main/scala/laserdisc/fs2/RedisClient.scala
  84. +3 −2 fs2/src/main/scala/laserdisc/fs2/Request.scala
  85. +4 −6 fs2/src/main/scala/laserdisc/fs2/exceptions.scala
  86. 0 fs2/src/main/{scala-2.12 → scala}/laserdisc/fs2/fs2.scala
  87. +2 −2 fs2/src/test/scala/laserdisc/fs2/RedisClientSpec.scala
@@ -1,4 +1,13 @@
**/target/
# Metals + Bloop
.metals/
.bloop/

# Intellij
.idea

# MacOS
*.DS_Store

# Anything else
**/target/
local.*
@@ -1,2 +1,2 @@
align = true # For pretty alignment.
maxColumn = 120 # For my wide 30" display.
maxColumn = 140 # For my wide 30" display.
@@ -4,7 +4,6 @@ sudo: false
language: scala
scala:
- 2.12.8
- 2.11.11-bin-typelevel-4

jdk:
- openjdk8
@@ -20,9 +20,7 @@ LaserDisc is a(nother) Scala driver for [Redis](https://redis.io/), written in S
It differentiates itself from the others for having a core layer, which is made up of all the supported Redis commands
and the Redis Serialization Protocol ([RESP](https://redis.io/topics/protocol)), that is strongly typed and which makes
heavy use of [shapeless](https://github.com/milessabin/shapeless) and [refined](https://github.com/fthomas/refined) to
achieve this. It's also worth noting that the core - in order to be built on scala 2.11.x - makes use of
[Typelevel's Scala 2.11](https://typelevel.org/scala) fork, since it requires the enhancements on implicit heuristics. Finally, it also provides an implementation of RESP built using
[scodec](http://scodec.org/).
achieve this. It also provides an implementation of RESP built using [scodec](http://scodec.org/).

On top of this, one or more clients can be implemented. The only one currently available out of the box is built using
[fs2](https://functional-streams-for-scala.github.io/fs2/)/[cats effect](https://typelevel.org/cats-effect/) but
@@ -48,7 +46,7 @@ Two reasons:

### Getting Started

LaserDisc is currently available for Scala 2.11 and 2.12 on the JVM.
LaserDisc is currently available for Scala 2.12 on the JVM.

Its core (protocol commands and RESP wire format) is also available for [Scala.JS](http://www.scala-js.org/).

@@ -69,7 +67,7 @@ Support for existing libraries is available via dedicated dependencies.
#### [Circe](https://circe.github.io/circe/)

When an `io.circe.Decoder[A]` and a `io.circe.Encoder[A]` are implicilty available,
instances of `Show[A]` and `Read[NonNullBulkString, A]` can be derived for free,
instances of `Show[A]` and `Read[Bulk, A]` can be derived for free,
just add the following in your `build.sbt`:

```
@@ -136,10 +134,10 @@ This should produce an output similar to the following one:
[info] Running Main
[info] - [ForkJoinPool-3-worker-2] Starting connection
[info] - [ForkJoinPool-3-worker-2] Server available for publishing: localhost:6379
[debug] - [ForkJoinPool-3-worker-5] sending Array(BulkString(SET),BulkString(a),BulkString(23))
[debug] - [ForkJoinPool-3-worker-0] receiving SimpleString(OK)
[debug] - [ForkJoinPool-3-worker-1] sending Array(BulkString(GET),BulkString(a))
[debug] - [ForkJoinPool-3-worker-5] receiving BulkString(23)
[debug] - [ForkJoinPool-3-worker-5] sending Arr(Bulk(SET),Bulk(a),Bulk(23))
[debug] - [ForkJoinPool-3-worker-0] receiving Str(OK)
[debug] - [ForkJoinPool-3-worker-1] sending Arr(Bulk(GET),Bulk(a))
[debug] - [ForkJoinPool-3-worker-5] receiving Bulk(23)
[info] - [ForkJoinPool-3-worker-2] yay!
[info] - [ForkJoinPool-3-worker-2] Shutting down connection
[info] - [ForkJoinPool-3-worker-0] Connection terminated: Right(())
@@ -1,18 +1,15 @@
package laserdisc.protocol
package laserdisc
package protocol

import org.openjdk.jmh.annotations.{Benchmark, Scope, State}
import eu.timepit.refined.auto._
import laserdisc.Maybe
import laserdisc.protocol.RESP._
import shapeless._

@State(Scope.Benchmark)
class ProtocolBench {

private final val protocol = Protocol("CUSTOM", _: Int :: String :: Long :: Double :: HNil).as[SimpleString, OK]
private final val protocol = Protocol("CUSTOM", _: Int :: String :: Long :: Double :: HNil).as[Str, OK]

private final val request = 0 :: "a" :: 1L :: 2.0d :: HNil
private final val response = str("OK")
private final val response = Str("OK")

@Benchmark def encode(): RESP = protocol(request).encode
@Benchmark def decode(): Maybe[OK] = protocol(request).decode(response)
@@ -1,8 +1,8 @@
package laserdisc.protocol
package laserdisc
package protocol

import java.nio.charset.StandardCharsets.UTF_8

import laserdisc.protocol.RESP._
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}
import scodec.bits.BitVector
import scodec.codecs.utf8
@@ -16,37 +16,37 @@ class RESPBench {
private final val chars = 2000

private final val ok = "OK"
private final val okRedis = s"+$ok\r\n"
private final val okRedis = s"+$ok$CRLF"
private final val rtProblem = "runtime problem"
private final val rtProblemRedis = s"-$rtProblem\r\n"
private final val rtProblemRedis = s"-$rtProblem$CRLF"
private final val fortyTwo = 42L
private final val fortyTwoRedis = s":$fortyTwo\r\n"
private final val fortyTwoRedis = s":$fortyTwo$CRLF"
private final val longString = new String(Array.fill(chars)('a'))
private final val longStringRedis = s"$$$chars\r\n$longString\r\n"
private final val longStringRedis = s"$$$chars$CRLF$longString$CRLF"
private final val longStringI =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

private final val simpleString = str(ok)
private final val simpleStringBits = BitVector(okRedis.getBytes(UTF_8))
private final val error = err(rtProblem)
private final val errorBits = BitVector(rtProblemRedis.getBytes(UTF_8))
private final val integer = int(fortyTwo)
private final val integerBits = BitVector(fortyTwoRedis.getBytes(UTF_8))
private final val bulkString = bulk(longString)
private final val bulkStringBits = BitVector(longStringRedis.getBytes(UTF_8))
private final val longStringBits = BitVector(longString.getBytes(UTF_8))
private final val longStringIBits = BitVector(longStringI.getBytes(UTF_8))
private final val str = Str(ok)
private final val strBits = BitVector(okRedis.getBytes(UTF_8))
private final val err = Err(rtProblem)
private final val errBits = BitVector(rtProblemRedis.getBytes(UTF_8))
private final val num = Num(fortyTwo)
private final val numBits = BitVector(fortyTwoRedis.getBytes(UTF_8))
private final val bulk = Bulk(longString)
private final val bulkBits = BitVector(longStringRedis.getBytes(UTF_8))
private final val longStringBits = BitVector(longString.getBytes(UTF_8))
private final val longStringIBits = BitVector(longStringI.getBytes(UTF_8))

@Benchmark def baseline_utf8_encode: Attempt[BitVector] = utf8.encode(longString)
@Benchmark def baseline_utf8_decode: Attempt[String] = utf8.decodeValue(longStringBits)
@Benchmark def baseline_utf8_encodeI: Attempt[BitVector] = utf8.encode(longStringI)
@Benchmark def baseline_utf8_decodeI: Attempt[String] = utf8.decodeValue(longStringIBits)
@Benchmark def simpleString_encode: Attempt[BitVector] = codec.encode(simpleString)
@Benchmark def simpleString_decode: Attempt[RESP] = codec.decodeValue(simpleStringBits)
@Benchmark def error_encode: Attempt[BitVector] = codec.encode(error)
@Benchmark def error_decode: Attempt[RESP] = codec.decodeValue(errorBits)
@Benchmark def integer_encode: Attempt[BitVector] = codec.encode(integer)
@Benchmark def integer_decode: Attempt[RESP] = codec.decodeValue(integerBits)
@Benchmark def bulkString_encode: Attempt[BitVector] = codec.encode(bulkString)
@Benchmark def bulkString_decode: Attempt[RESP] = codec.decodeValue(bulkStringBits)
@Benchmark def str_encode: Attempt[BitVector] = codec.encode(str)
@Benchmark def str_decode: Attempt[RESP] = codec.decodeValue(strBits)
@Benchmark def err_encode: Attempt[BitVector] = codec.encode(err)
@Benchmark def err_decode: Attempt[RESP] = codec.decodeValue(errBits)
@Benchmark def num_encode: Attempt[BitVector] = codec.encode(num)
@Benchmark def num_decode: Attempt[RESP] = codec.decodeValue(numBits)
@Benchmark def bulk_encode: Attempt[BitVector] = codec.encode(bulk)
@Benchmark def bulk_decode: Attempt[RESP] = codec.decodeValue(bulkBits)
}
@@ -1,4 +1,5 @@
package laserdisc.protocol
package laserdisc
package protocol

import org.openjdk.jmh.annotations.{Benchmark, Scope, State}
import shapeless._
@@ -10,5 +11,5 @@ class RESPParamWriteBench {

private final val value = 0 :: "a" :: 1L :: 2.0d :: HNil

@Benchmark def write(): Seq[BulkString] = respParamWrite.write(value)
@Benchmark def write(): Seq[GenBulk] = respParamWrite.write(value)
}
@@ -1,4 +1,5 @@
package laserdisc.protocol
package laserdisc
package protocol

import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets.UTF_8
@@ -1,44 +1,39 @@
import sbtcrossproject.CrossPlugin.autoImport.crossProject
import sbtcrossproject.CrossType
// shadow sbt-scalajs' crossProject and CrossType from Scala.js 0.6.x
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}

val `scala 211` = "2.11.11-bin-typelevel-4"
val `scala 212` = "2.12.8"
val `scala 2.12` = "2.12.8"

val V = new {
val circe = "0.11.1"
val fs2 = "1.0.5"
val `kind-projector` = "0.9.10"
val kittens = "1.2.1"
val `log-effect-fs2` = "0.8.0"
val refined = "0.9.9"
val refined211 = "0.8.7"
val scalacheck = "1.13.5"
val scalacheck = "1.14.0"
val scalatest = "3.0.8"
val `scodec-bits` = "1.1.12"
val `scodec-core` = "1.11.4"
val `scodec-stream` = "1.2.1"
val shapeless = "2.3.3"
val `log-effect-fs2` = "0.8.0"
}

val `circe-core` = Def.setting("io.circe" %%% "circe-core" % V.circe)
val `circe-parser` = Def.setting("io.circe" %%% "circe-parser" % V.circe)
val `fs2-core` = Def.setting("co.fs2" %%% "fs2-core" % V.fs2)
val `fs2-io` = Def.setting("co.fs2" %% "fs2-io" % V.fs2)
val kittens = Def.setting("org.typelevel" %%% "kittens" % V.kittens)
val `scodec-bits` = Def.setting("org.scodec" %%% "scodec-bits" % V.`scodec-bits`)
val `scodec-core` = Def.setting("org.scodec" %%% "scodec-core" % V.`scodec-core`)
val `scodec-stream` = Def.setting("org.scodec" %%% "scodec-stream" % V.`scodec-stream`)
val shapeless = Def.setting("com.chuusai" %%% "shapeless" % V.shapeless)
val `log-effect-fs2` = Def.setting("io.laserdisc" %%% "log-effect-fs2" % V.`log-effect-fs2`)
val `circe-generic` = Def.setting("io.circe" %%% "circe-generic" % V.circe % Test)
val scalacheck = Def.setting("org.scalacheck" %%% "scalacheck" % V.scalacheck % Test)
val scalatest = Def.setting("org.scalatest" %%% "scalatest" % V.scalatest % Test)
val refined = Def.setting {
is211.value match {
case true => "eu.timepit" %%% "refined" % V.refined211
case _ => "eu.timepit" %%% "refined" % V.refined
}
}
val `circe-core` = Def.setting("io.circe" %%% "circe-core" % V.circe)
val `circe-parser` = Def.setting("io.circe" %%% "circe-parser" % V.circe)
val `fs2-core` = Def.setting("co.fs2" %%% "fs2-core" % V.fs2)
val `fs2-io` = Def.setting("co.fs2" %% "fs2-io" % V.fs2)
val kittens = Def.setting("org.typelevel" %%% "kittens" % V.kittens)
val `log-effect-fs2` = Def.setting("io.laserdisc" %%% "log-effect-fs2" % V.`log-effect-fs2`)
val refined = Def.setting("eu.timepit" %%% "refined" % V.refined)
val `scodec-bits` = Def.setting("org.scodec" %%% "scodec-bits" % V.`scodec-bits`)
val `scodec-core` = Def.setting("org.scodec" %%% "scodec-core" % V.`scodec-core`)
val `scodec-stream` = Def.setting("org.scodec" %%% "scodec-stream" % V.`scodec-stream`)
val shapeless = Def.setting("com.chuusai" %%% "shapeless" % V.shapeless)

val `circe-generic` = Def.setting("io.circe" %%% "circe-generic" % V.circe % Test)
val `refined-scalacheck` = Def.setting("eu.timepit" %%% "refined-scalacheck" % V.refined % Test)
val scalacheck = Def.setting("org.scalacheck" %%% "scalacheck" % V.scalacheck % Test)
val scalatest = Def.setting("org.scalatest" %%% "scalatest" % V.scalatest % Test)

val `kind-projector-compiler-plugin` = Def.setting {
compilerPlugin("org.spire-math" % "kind-projector" % V.`kind-projector` cross CrossVersion.binary)
@@ -54,6 +49,7 @@ val coreDeps = Def.Initialize.join {
`scodec-core`,
shapeless,
refined,
`refined-scalacheck`,
scalacheck,
scalatest
)
@@ -65,8 +61,8 @@ val fs2Deps = Def.Initialize.join {
`fs2-io`,
`kind-projector-compiler-plugin`,
kittens,
`scodec-stream`,
`log-effect-fs2`,
`scodec-stream`,
scalacheck,
scalatest
)
@@ -113,7 +109,7 @@ val externalApiMappings = Def.task {
}

val versionDependantScalacOptions = Def.setting {
def versionDependent(scalaVersion: String, flags: Seq[String]) =
def versionDependent(scalaVersion: String, flags: Seq[String]) =
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, major)) if major >= 12 =>
flags ++ Seq(
@@ -126,11 +122,9 @@ val versionDependantScalacOptions = Def.setting {
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
)
case _ =>
(flags ++ Seq("-Yinduction-heuristics", "-Yliteral-types"))
.filterNot(_ == "-Xlint:missing-interpolator") //@implicitNotFound uses ${A} syntax w/o need for s interpolator
case _ => flags
}

val flags = Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding",
@@ -168,7 +162,7 @@ val versionDependantScalacOptions = Def.setting {
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Ywarn-nullary-unit", // Warn when nullary methods return Unit.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-numeric-widen" // Warn when numerics are widened.
)

versionDependent(scalaVersion.value, flags)
@@ -177,17 +171,13 @@ val versionDependantScalacOptions = Def.setting {
inThisBuild {
Def.settings(
organization := "io.laserdisc",
scalaVersion := `scala 212`
scalaVersion := `scala 2.12`
)
}

lazy val commonSettings = Seq(
scalaOrganization :=
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => "org.typelevel"
case _ => "org.scala-lang"
}),
crossScalaVersions := Seq(`scala 211`, `scala 212`),
scalaOrganization := "org.scala-lang",
crossScalaVersions := Seq(`scala 2.12`),
scalacOptions ++= versionDependantScalacOptions.value,
Compile / console / scalacOptions --= Seq("-Ywarn-unused:imports", "-Xfatal-warnings"),
Test / console / scalacOptions := (Compile / console / scalacOptions).value
@@ -237,18 +227,8 @@ lazy val scoverageSettings = Seq(
coverageMinimum := 60,
coverageFailOnMinimum := false,
coverageHighlighting := true,
coverageEnabled := {
if (is211.value) false else coverageEnabled.value
}
)

lazy val is211 = Def.setting {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => true
case _ => false
}
}

lazy val allSettings = commonSettings ++ testSettings ++ scaladocSettings ++ publishSettings ++ scoverageSettings

lazy val scalaJsTLSSettings = Seq(
@@ -265,7 +245,8 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
.settings(
name := "laserdisc-core",
libraryDependencies ++= coreDeps.value,
Compile / boilerplateSource := baseDirectory.value.getParentFile / "src" / "main" / "boilerplate"
Compile / boilerplateSource := baseDirectory.value.getParentFile / "src" / "main" / "boilerplate",
Test / boilerplateSource := baseDirectory.value.getParentFile / "src" / "test" / "boilerplate"
)
.jvmSettings(
javaOptions += "-Djava.net.preferIPv4Stack=true",
@@ -311,7 +292,7 @@ lazy val cli = project

lazy val circe = crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.crossType(CrossType.Pure)
.in(file("circe"))
.dependsOn(core)
.settings(allSettings)
@@ -321,13 +302,10 @@ lazy val circe = crossProject(JSPlatform, JVMPlatform)
)
.jsSettings(scalaJsTLSSettings: _*)

lazy val circeJVM = circe.jvm
lazy val circeJS = circe.js

lazy val laserdisc = project
.in(file("."))
.aggregate(coreJVM, coreJS, fs2, cli, circeJVM, circeJS)
.aggregate(coreJVM, coreJS, fs2, cli, circe.jvm, circe.js)
.settings(publishSettings)
.settings(
publishArtifact := false
)
)
@@ -3,12 +3,11 @@ package interop

import io.circe._
import io.circe.syntax._
import laserdisc.protocol.NonNullBulkString

object circe {
implicit final def encoderShow[A: Encoder]: Show[A] = Show.instance(_.asJson.noSpaces)
implicit final def decoderRead[A: Decoder]: Read[NonNullBulkString, A] = Read.instance {
case NonNullBulkString(s) =>
implicit final def decoderRead[A: Decoder]: Bulk ==> A = Read.instance {
case Bulk(s) =>
parser.decode(s) match {
case Right(a) => Some(a)
case _ => None

0 comments on commit d530ae7

Please sign in to comment.
You can’t perform that action at this time.