Skip to content

Commit

Permalink
Proper package naming convention, works for s2
Browse files Browse the repository at this point in the history
  • Loading branch information
agrodowski committed Mar 5, 2024
1 parent c4cda0a commit abc397f
Show file tree
Hide file tree
Showing 236 changed files with 483 additions and 483 deletions.
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ or for tagged-types code generation support
`libraryDependencies += "pl.iterators" %% "kebs-tagged-meta" % "1.9.6"`
`addCompilerPlugin("org.scalameta" % "paradise" % "3.0.0-M11" cross CrossVersion.full)`

Support for `instances`
Support for `pl.iterators.kebs.json.instances`

`libraryDependencies += "pl.iterators" %% "kebs-instances" % "1.9.6"`
`libraryDependencies += "pl.iterators" %% "kebs-pl.iterators.kebs.json.instances" % "1.9.6"`

Builds for Scala `2.12` and `2.13` are provided.

Expand Down Expand Up @@ -172,7 +172,7 @@ class People(tag: Tag) extends Table[Person](tag, "people") {
If you prefer to **mix in trait** instead of import (for example you're using a custom driver like `slick-pg`), you can do it as well:

```scala
import pl.iterators.kebs.Kebs
import pl.iterators.kebs.slick.Kebs
object MyPostgresProfile extends ExPostgresDriver with PgArraySupport {
override val api: API = new API {}
trait API extends super.API with ArrayImplicits with Kebs
Expand Down Expand Up @@ -295,7 +295,7 @@ class HstoreRepository(implicit ec: ExecutionContext) {
}

```
Make sure to mix in correct mapping from `instances`, in this case `YearMonthString`.
Make sure to mix in correct mapping from `pl.iterators.kebs.json.instances`, in this case `YearMonthString`.


**`kebs` also supports `Enumeratum`**
Expand Down Expand Up @@ -362,8 +362,8 @@ If you import `enums.lowercase._` or `enums.uppercase._` then it'll save enum na
Of course, enums also work with traits:

```scala
import pl.iterators.kebs.Kebs
import pl.iterators.kebs.enums.KebsEnums
import pl.iterators.kebs.slick.Kebs
import pl.iterators.kebs.slick.enums.KebsEnums

object MyPostgresProfile extends ExPostgresDriver {
override val api: API = new API {}
Expand All @@ -388,14 +388,14 @@ import MyPostgresProfile.api._

#### - kebs generates doobie mappers for your case-class wrappers (kebs-doobie)

kebs-doobie works similarly to [kebs-slick](#--kebs-generates-slick-mappers-for-your-case-class-wrappers-kebs-slick). It provides doobie's `Meta` instances for:
kebs-doobie works similarly to [kebs-slick](#--kebs-generates-slick-mappers-for-your-case-class-wrappers-kebs-slick). It provides doobie's `Meta` pl.iterators.kebs.json.instances for:

* Instances of `ValueClassLike` (value classes, tagged types, opaque types)
* Instances of `InstanceConverter`
* Enumeratum for Scala 2
* Native enums for Scala 3

To make the magic happen, do `import pl.iterators.kebs._` and `import pl.iterators.kebs.enums._` (or `import pl.iterators.kebs.enums.uppercase._` or `import pl.iterators.kebs.enums.lowercase._`).
To make the magic happen, do `import pl.iterators.kebs._` and `import pl.iterators.kebs.slick.enums._` (or `import pl.iterators.kebs.slick.enums.uppercase._` or `import pl.iterators.kebs.slick.enums.lowercase._`).

#### - kebs eliminates spray-json induced boilerplate (kebs-spray-json)

Expand Down Expand Up @@ -475,7 +475,7 @@ object ThingProtocol extends JsonProtocol with KebsSpray
```

If you want to further eliminate boilerplate generated by `JsonProtocol` itself, you can import traits
from `kebs-instances` you need and then `ThingProtocol` looks like this:
from `kebs-pl.iterators.kebs.json.instances` you need and then `ThingProtocol` looks like this:

```scala
object ThingProtocol extends DefaultJsonProtocol with SprayJsonSupport with KebsSpray with URIString with UUIDString
Expand Down Expand Up @@ -685,7 +685,7 @@ case class R(a: Int, rs: Seq[R]) derives Decoder, Encoder.AsObject
```


3. If you're using flat format or Snakified/Capitalized formats, remember to import `given` instances, e.g.:
3. If you're using flat format or Snakified/Capitalized formats, remember to import `given` pl.iterators.kebs.json.instances, e.g.:
```scala
object KebsProtocol extends KebsCirce with KebsCirce.Snakified
import KebsProtocol.{given, _}
Expand Down Expand Up @@ -751,7 +751,7 @@ import org.http4s.implicits._

import pl.iterators.kebs.opaque.Opaque
import pl.iterators.kebs.http4s.{given, _}
import pl.iterators.kebs.instances.KebsInstances._ // optional, if you want instances support, ex. java.util.Currency
import pl.iterators.kebs.pl.iterators.kebs.json.instances.KebsInstances._ // optional, if you want pl.iterators.kebs.json.instances support, ex. java.util.Currency

opaque type Age = Int
object Age extends Opaque[Age, Int] {
Expand Down Expand Up @@ -787,7 +787,7 @@ for more details.

Starting with version 1.6.0, kebs contain an implementation of, so-called, `tagged types`. If you want to know what a `tagged type` is, please see eg.
[Introduction to Tagged Types](http://www.vlachjosef.com/tagged-types-introduction/) or [Scalaz tagged types description](http://eed3si9n.com/learning-scalaz/Tagged+type.html).
In general, taggging of a type is a mechanism for distinguishing between various instances of the same type. For instance, you might want to use an `Int` to represent an _user id_ or _purchase id_.
In general, taggging of a type is a mechanism for distinguishing between various pl.iterators.kebs.json.instances of the same type. For instance, you might want to use an `Int` to represent an _user id_ or _purchase id_.
But if you use _just an Int_ the compiler will not protest if you use _purchase id_ integer in place of _user id_ integer and vice versa.
To gain additional type safety you could use 1-element case-class wrappers, or, tagged types. In short, you would create `Int @@ UserId` and `Int @@ PurchaseId` types,
where `@@` is _tag_ operator. Thus, you can distinguish between various usages of `Int` while still retaining all `Int` properties ie. `Int @@ UserId` is still an `Int`, but it is not `Int @@ PurchaseId`.
Expand Down Expand Up @@ -1045,7 +1045,7 @@ object Sample extends KebsJsonSchema {

**Still at experimental stage.**

Kebs provides support to use tagged types in your Arbitrary instances from ScalaCheck.
Kebs provides support to use tagged types in your Arbitrary pl.iterators.kebs.json.instances from ScalaCheck.
Additionally, Kebs provides support for Java types.
Kebs also introduces term of minimal and maximal generator.
The minimal generator is a generator which always generates empty collection of Option, Set, Map etc.
Expand Down Expand Up @@ -1110,9 +1110,8 @@ You can also use this web page: https://plugins.jetbrains.com/plugin/16069-kebs.
### Kebs 2.0 migration guide

Please be aware that recent changes in the source code might require some changes in your codebase. Follow the guide below to migrate your code to Kebs 2.0:
* Rename `pl.iterators.kebs.macros.CaseClass1Rep` to `pl.iterators.kebs.macros.ValueClassLike`.
* In cases where previously an implicit conversion from a 1-element case class to a `ValueClassLike` occured, please mix in the `CaseClass1ToValueClass` trait.
* Extend your value-enums with `pl.iterators.kebs.enums.ValueEnumLikeEntry` parameterized with the type of the value.
* If you are using value classes instead of tagged/opaque types, please mix in the `CaseClass1ToValueClass` trait.
* Extend your value-enums with `pl.iterators.kebs.slick.enums.ValueEnumLikeEntry` parameterized with the type of the value.
* Native Scala 3 value-enums:
```scala
enum ColorButRGB(val value: Int) extends ValueEnumLikeEntry[Int] {
Expand All @@ -1135,6 +1134,6 @@ Please be aware that recent changes in the source code might require some change
* Extend your traits/classes/objects, if inside of one an implicit enum (or value-enum) conversion for `kebs` library's needs should occur, with one of the following traits:
* For Scala 2 and Scala 3 enums from `enumeratum` library: `pl.iterators.kebs.enumeratum.KebsEnumeratum`
* For Scala 2 and Scala 3 value-enums from `enumeratum` library: `pl.iterators.kebs.enumeratum.KebsValueEnumeratum`
* For Scala 3 native value-enums: `pl.iterators.kebs.enums.KebsValueEnum`
* For Scala 3 native value-enums: `pl.iterators.kebs.slick.enums.KebsValueEnum`
* For Scala 2 `scala.Enumeration` enums or Scala 3 native enums: `pl.iterators.kebs.enums.KebsEnum`

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pl.iterators.kebs.matchers
package pl.iterators.kebs.akkahttp.matchers

import akka.http.scaladsl.server.{PathMatcher1, PathMatchers}
import enumeratum.{Enum, EnumEntry}
import pl.iterators.kebs.instances.InstanceConverter
import pl.iterators.kebs.macros.ValueClassLike
import pl.iterators.kebs.core.instances.InstanceConverter
import pl.iterators.kebs.core.macros.ValueClassLike

import scala.language.implicitConversions

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package pl.iterators.kebs
package pl.iterators.kebs.akkahttp

package object matchers extends KebsMatchers
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pl.iterators.kebs.unmarshallers
package pl.iterators.kebs.akkahttp.unmarshallers

import akka.http.scaladsl.unmarshalling.{FromStringUnmarshaller, Unmarshaller}
import pl.iterators.kebs.instances.InstanceConverter
import pl.iterators.kebs.macros.{ValueClassLike, CaseClass1ToValueClass}
import pl.iterators.kebs.core.instances.InstanceConverter
import pl.iterators.kebs.core.macros.{CaseClass1ToValueClass, ValueClassLike}

trait KebsUnmarshallers extends CaseClass1ToValueClass {
implicit def kebsUnmarshaller[A, B](implicit rep: ValueClassLike[B, A]): Unmarshaller[A, B] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pl.iterators.kebs.unmarshallers.enums
package pl.iterators.kebs.akkahttp.unmarshallers.enums

import akka.http.scaladsl.unmarshalling.PredefinedFromStringUnmarshallers._
import akka.http.scaladsl.unmarshalling.{FromStringUnmarshaller, Unmarshaller}
import akka.http.scaladsl.util.FastFuture
import pl.iterators.kebs.enums.{EnumLike, ValueEnumLike, ValueEnumLikeEntry}
import pl.iterators.kebs.core.enums.{EnumLike, ValueEnumLike, ValueEnumLikeEntry}

trait EnumUnmarshallers {
final def enumUnmarshaller[E](`enum`: EnumLike[E]): FromStringUnmarshaller[E] = Unmarshaller { _ =>name =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package pl.iterators.kebs.unmarshallers
package pl.iterators.kebs.akkahttp.unmarshallers

package object enums extends KebsEnumUnmarshallers
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package pl.iterators.kebs
package pl.iterators.kebs.akkahttp

package object unmarshallers extends KebsUnmarshallers
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package pl.iterators.kebs.domain
package pl.iterators.kebs.akkahttp.domain

import enumeratum.values.{IntEnum, IntEnumEntry, StringEnum, StringEnumEntry}
import enumeratum.{Enum, EnumEntry}
import pl.iterators.kebs.tag.meta.tagged
import pl.iterators.kebs.tagged._
import pl.iterators.kebs.enums.ValueEnumLikeEntry
import pl.iterators.kebs.core.enums.ValueEnumLikeEntry

import java.net.URI
import java.util.UUID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package pl.iterators.kebs.matchers
package pl.iterators.kebs.akkahttp.matchers

import akka.http.scaladsl.server.Directives
import akka.http.scaladsl.testkit.ScalatestRouteTest
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import pl.iterators.kebs.domain.Domain._
import pl.iterators.kebs.akkahttp.domain.Domain.Greeting
import pl.iterators.kebs.akkahttp.domain.Domain._
import pl.iterators.kebs.instances.net.URIString
import pl.iterators.kebs.instances.time.mixins.InstantEpochMilliLong
import pl.iterators.kebs.instances.time.{DayOfWeekInt, ZonedDateTimeString}
import pl.iterators.kebs.instances.time.mixins.InstantEpochMilliLong

import java.net.URI
import java.time.{DayOfWeek, Instant, ZonedDateTime}
Expand All @@ -25,7 +26,7 @@ class AkkaHttpMatchersTests
with URIString {

test("No ValueClassLike implicits derived") {
import pl.iterators.kebs.macros.ValueClassLike
import pl.iterators.kebs.core.macros.ValueClassLike

"implicitly[ValueClassLike[DayOfWeek, Int]]" shouldNot typeCheck
"implicitly[ValueClassLike[Int, DayOfWeek]]" shouldNot typeCheck
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.iterators.kebs.unmarshallers
package pl.iterators.kebs.akkahttp.unmarshallers

import akka.http.scaladsl.model.FormData
import akka.http.scaladsl.server.{Directives, MalformedQueryParamRejection}
Expand All @@ -7,12 +7,16 @@ import akka.http.scaladsl.unmarshalling.Unmarshal
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import pl.iterators.kebs.domain.Domain._
import pl.iterators.kebs.akkahttp.domain.Domain.{Blue, Color, Green, Greeting, I, LibraryItem, P, Red, S, ShirtSize, SortOrder}
import pl.iterators.kebs.akkahttp.unmarshallers.KebsUnmarshallers
import pl.iterators.kebs.akkahttp.domain.Domain._
import pl.iterators.kebs.instances.net.URIString
import pl.iterators.kebs.instances.time.{DayOfWeekInt, YearMonthString}
import pl.iterators.kebs.enumeratum.{KebsEnumeratum, KebsValueEnumeratum}
import pl.iterators.kebs.instances.net.URIString
import pl.iterators.kebs.instances.time.{DayOfWeekInt, YearMonthString}
import pl.iterators.kebs.unmarshallers.enums.KebsEnumUnmarshallers
import pl.iterators.kebs.enums.ValueEnumLikeEntry
import pl.iterators.kebs.akkahttp.unmarshallers.enums.KebsEnumUnmarshallers
import pl.iterators.kebs.core.enums.ValueEnumLikeEntry

import java.time.{DayOfWeek, YearMonth}

Expand All @@ -31,7 +35,7 @@ class AkkaHttpUnmarshallersTests
with KebsValueEnumeratum {

test("No ValueClassLike implicits derived") {
import pl.iterators.kebs.macros.ValueClassLike
import pl.iterators.kebs.core.macros.ValueClassLike

"implicitly[ValueClassLike[URI, String]]" shouldNot typeCheck
"implicitly[ValueClassLike[String, URI]]" shouldNot typeCheck
Expand Down Expand Up @@ -130,7 +134,7 @@ class AkkaHttpUnmarshallersTests
Get("/color?red=1&green=2&blue=3") ~> route ~> check { responseAs[String] shouldEqual "Color(Red(1),Green(2),Blue(3))" }
}

test("Unmarshalling instances parameter") {
test("Unmarshalling pl.iterators.kebs.json.instances parameter") {
val testRoute = path("instances") {
parameters(Symbol("year").as[YearMonth]) { year =>
complete(year.toString)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.iterators.kebs_benchmarks
package pl.iterators.kebs.benchmarks

import java.time.format.DateTimeFormatter
import java.time.{LocalDate, LocalTime}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package pl.iterators.kebs.circe

import io.circe.generic.AutoDerivation
import io.circe.{Decoder, Encoder}
import pl.iterators.kebs.instances.InstanceConverter
import pl.iterators.kebs.macros.{ValueClassLike, CaseClass1ToValueClass}
import pl.iterators.kebs.core.instances.InstanceConverter
import pl.iterators.kebs.core.macros.{CaseClass1ToValueClass, ValueClassLike}

import scala.language.experimental.macros
import scala.util.Try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package pl.iterators.kebs.circe

import io.circe.generic.extras.Configuration
import io.circe.{Decoder, Encoder}
import pl.iterators.kebs.macros.MacroUtils
import pl.iterators.kebs.core.macros.MacroUtils
import pl.iterators.kebs.core.macros.namingconventions.SnakifyVariant.snakify

import scala.collection.immutable.Seq
import scala.reflect.macros.whitebox
Expand Down Expand Up @@ -110,7 +111,6 @@ object KebsCirceMacros {

class SnakifyVariant(context: whitebox.Context) extends KebsCirceMacros(context) {

import pl.iterators.kebs.macros.namingconventions.SnakifyVariant.snakify
import c.universe._
protected override val semiAutoNamingStrategy: Tree =
q"implicit lazy val __config: _root_.io.circe.generic.extras.Configuration = _root_.io.circe.generic.extras.Configuration.default.withSnakeCaseMemberNames"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pl.iterators.kebs.circe

import io.circe.Decoder.Result
import io.circe._
import pl.iterators.kebs.enums.{EnumLike, ValueEnumLike, ValueEnumLikeEntry}
import pl.iterators.kebs.core.enums.{EnumLike, ValueEnumLike, ValueEnumLikeEntry}

trait CirceEnum {
@inline protected final def enumNameDeserializationError[E](`enum`: EnumLike[E], name: String): String = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import scala.deriving._
import scala.util.Try
import scala.quoted.Quotes
import io.circe.HCursor
import pl.iterators.kebs.macros.{ValueClassLike, CaseClass1ToValueClass}
import pl.iterators.kebs.instances.InstanceConverter
import io.circe.generic.AutoDerivation
import scala.quoted.Type
import io.circe.derivation.ConfiguredDecoder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.circe.Decoder.Result
import io.circe._
import scala.reflect.Enum
import scala.util.Try
import pl.iterators.kebs.enums.{ValueEnumLike, ValueEnumLikeEntry, EnumLike}

import reflect.Selectable.reflectiveSelectable

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import enumeratum.{Enum, EnumEntry}
package pl.iterators.kebs.circe

import _root_.enumeratum.{Enum, EnumEntry}
import io.circe._
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import org.scalatest.funsuite.AnyFunSuite
import pl.iterators.kebs.circe.KebsEnumFormats
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io.circe.generic.extras.decoding.ConfiguredDecoder
import io.circe.{Decoder, Encoder, Json, JsonNumber}
package pl.iterators.kebs.circe

import io.circe.{Decoder, Encoder, Json}
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import pl.iterators.kebs.circe.KebsCirce
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package pl.iterators.kebs.circe

import io.circe.parser.parse
import io.circe.{Decoder, Encoder, Json}
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package pl.iterators.kebs.circe

import io.circe.{Decoder, Encoder, Json}
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import java.time.ZonedDateTime
package pl.iterators.kebs.circe

import io.circe.{Decoder, Encoder, Json}
import org.scalatest.funsuite.AnyFunSuite
import pl.iterators.kebs.circe.KebsCirce
import org.scalatest.matchers.should.Matchers

import java.time.ZonedDateTime

class CirceFormatTests extends AnyFunSuite with Matchers {
object KebsProtocol extends KebsCirce
import KebsProtocol._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import enumeratum.values.{LongEnum, LongEnumEntry}
package pl.iterators.kebs.circe

import _root_.enumeratum.values.{LongEnum, LongEnumEntry}
import io.circe._
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import pl.iterators.kebs.circe.KebsEnumFormats
import pl.iterators.kebs.enumeratum.KebsValueEnumeratum
import pl.iterators.kebs.enums.ValueEnumLikeEntry
import pl.iterators.kebs.core.enums.ValueEnumLikeEntry

class CirceValueEnumDecoderEncoderTests extends AnyFunSuite with Matchers with KebsValueEnumeratum {
sealed abstract class LongGreeting(val value: Long) extends LongEnumEntry with ValueEnumLikeEntry[Long]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

package pl.iterators.kebs.circe.instances

import io.circe.{Decoder, Encoder, Json}
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import pl.iterators.kebs.circe.KebsCirce
import pl.iterators.kebs.instances.time.LocalDateTimeString
import pl.iterators.kebs.instances.time.mixins.{DurationNanosLong, InstantEpochMilliLong}
import pl.iterators.kebs.instances.{InstanceConverter, TimeInstances}
import pl.iterators.kebs.core.instances.InstanceConverter
import pl.iterators.kebs.instances.TimeInstances

import java.time._
import java.time.format.DateTimeFormatter
Expand Down
Loading

0 comments on commit abc397f

Please sign in to comment.