This repository has been archived by the owner on Jul 14, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,558 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Scala CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: olafurpg/setup-scala@v10 | ||
- name: Run tests | ||
run: sbt ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
*.class | ||
*.log | ||
|
||
.vscode | ||
.idea | ||
.bloop | ||
.bsp | ||
.metals | ||
|
||
metals.sbt | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version = 3.5.3 | ||
style = default | ||
maxColumn = 120 | ||
align.preset = none | ||
docstrings.blankFirstLine = yes | ||
docstrings.style = Asterisk | ||
docstrings.oneline = unfold | ||
docstrings.wrap = no | ||
trailingCommas = always | ||
runner.dialect = scala3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,25 @@ | ||
# snowflake4s | ||
Functional snowflake id generator | ||
|
||
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/qwbarch/snowflake4s/Scala%20CI?logo=github)](https://github.com/qwbarch/snowflake4s/actions/workflows/scala.yml) | ||
[![snowflake4s Scala version support](https://index.scala-lang.org/qwbarch/snowflake4s/snowflake4s/latest-by-scala-version.svg)](https://index.scala-lang.org/qwbarch/snowflake4s/snowflake4s) | ||
[![scaladoc](https://javadoc.io/badge2/io.github.qwbarch/snowflake4s_3/scaladoc.svg)](https://javadoc.io/doc/io.github.qwbarch/snowflake4s_3) | ||
[![license](https://img.shields.io/badge/license-MIT-green)](https://opensource.org/licenses/MIT) | ||
[![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org) | ||
|
||
Visit the [microsite](https://qwbarch.github.io/snowflake4s/) for more information. | ||
|
||
## Quickstart | ||
|
||
```scala | ||
libraryDependencies += "io.github.qwbarch" %% "snowflake4s" % "1.1.0-RC1" | ||
``` | ||
|
||
## Library integration | ||
|
||
```scala | ||
libraryDependencies ++= Seq( | ||
"io.github.qwbarch" %% "snowflake4s-circe" % "1.1.0-RC1", | ||
"io.github.qwbarch" %% "snowflake4s-skunk" % "1.1.0-RC1", | ||
"io.github.qwbarch" %% "snowflake4s-http4s" % "1.1.0-RC1", | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
import Dependency._ | ||
import ReleaseTransformations._ | ||
|
||
lazy val commonSettings: Seq[SettingsDefinition] = Seq( | ||
organization := "io.github.qwbarch", | ||
scalaVersion := "3.1.2", | ||
crossScalaVersions := Seq("3.1.2", "2.13.8", "2.12.15"), | ||
testFrameworks += new TestFramework("weaver.framework.CatsEffect"), | ||
libraryDependencies ++= Seq( | ||
log4CatsNoOp % Test, | ||
weaverCats % Test, | ||
weaverScalaCheck % Test, | ||
), | ||
// Enable Ymacro-annotations for scala 2.13, required for newtypes | ||
scalacOptions ++= { | ||
CrossVersion.partialVersion(scalaVersion.value) match { | ||
case Some((2, 13)) => "-Ymacro-annotations" :: Nil | ||
case _ => Nil | ||
} | ||
}, | ||
// Enable some scala 3 syntax for scala 2.12 and 2.13 | ||
scalacOptions ++= { | ||
CrossVersion.partialVersion(scalaVersion.value) match { | ||
case Some((2, _)) => "-Xsource:3" :: Nil | ||
case _ => Nil | ||
} | ||
}, | ||
// Enable better-monadic-for with non-dotty versions | ||
libraryDependencies ++= { | ||
CrossVersion.partialVersion(scalaVersion.value) match { | ||
case Some((2, _)) => compilerPlugin(betterMonadicFor) :: Nil | ||
case _ => Nil | ||
} | ||
}, | ||
) | ||
|
||
lazy val root = (project in file(".")) | ||
.settings(commonSettings ++ noPublishSettings ++ releaseSettings: _*) | ||
.settings( | ||
Compile / unmanagedSourceDirectories := Nil, | ||
Test / unmanagedSourceDirectories := Nil, | ||
) | ||
.aggregate(core, circe, skunk, http4s) | ||
|
||
lazy val core = (project in file("modules/core")) | ||
.settings(commonSettings ++ publishSettings: _*) | ||
.settings( | ||
name := "snowflake4s", | ||
libraryDependencies ++= Seq( | ||
catsCore, | ||
catsKernel, | ||
catsEffectKernel, | ||
log4CatsCore, | ||
), | ||
// Use newtypes for scala 2.13 | ||
libraryDependencies ++= { | ||
CrossVersion.partialVersion(scalaVersion.value) match { | ||
case Some((2, 13)) => newType :: Nil | ||
case _ => Nil | ||
} | ||
}, | ||
) | ||
|
||
lazy val circe = (project in file("modules/circe")) | ||
.dependsOn(core % "compile->compile;test->test") | ||
.settings(commonSettings ++ publishSettings: _*) | ||
.settings( | ||
name := "snowflake4s-circe", | ||
libraryDependencies += circeCore, | ||
) | ||
|
||
lazy val skunk = (project in file("modules/skunk")) | ||
.dependsOn(core % "compile->compile;test->test") | ||
.settings(commonSettings ++ publishSettings: _*) | ||
.settings( | ||
name := "snowflake4s-skunk", | ||
libraryDependencies += skunkCore, | ||
) | ||
|
||
lazy val http4s = (project in file("modules/http4s")) | ||
.dependsOn(core % "compile->compile;test->test") | ||
.dependsOn(circe % "test->test") | ||
.settings(commonSettings ++ publishSettings: _*) | ||
.settings( | ||
name := "snowflake4s-http4s", | ||
libraryDependencies ++= Seq( | ||
http4sCore, | ||
http4sDsl % Test, | ||
http4sCirce % Test, | ||
), | ||
) | ||
|
||
lazy val docs = (project in file("modules/docs")) | ||
.dependsOn(core) | ||
.enablePlugins(ParadoxPlugin) | ||
.enablePlugins(ParadoxSitePlugin) | ||
.enablePlugins(GhpagesPlugin) | ||
.settings(commonSettings ++ noPublishSettings: _*) | ||
.settings( | ||
scalacOptions := Nil, | ||
git.remoteRepo := "git@github.com:qwbarch/snowflake4s.git", | ||
ghpagesNoJekyll := true, | ||
paradoxTheme := Some(builtinParadoxTheme("generic")), | ||
paradoxProperties ++= Map( | ||
"organization" -> organization.value, | ||
"version" -> version.value, | ||
), | ||
) | ||
|
||
lazy val publishSettings = | ||
releaseSettings ++ sharedPublishSettings ++ credentialSettings ++ sharedReleaseProcess | ||
|
||
lazy val credentialSettings = Seq( | ||
credentials ++= | ||
(for { | ||
username <- Option(System.getenv().get("SONATYPE_USERNAME")) | ||
password <- Option(System.getenv().get("SONATYPE_PASSWORD")) | ||
} yield Credentials( | ||
"Sonatype Nexus Repository Manager", | ||
"oss.sonatype.org", | ||
username, | ||
password, | ||
)).toSeq, | ||
) | ||
|
||
lazy val noPublishSettings = Seq( | ||
publish := (()), | ||
publishLocal := (()), | ||
publishArtifact := false, | ||
publish / skip := true, | ||
) | ||
|
||
lazy val sharedReleaseProcess = Seq( | ||
releaseProcess := Seq[ReleaseStep]( | ||
checkSnapshotDependencies, | ||
inquireVersions, | ||
runClean, | ||
runTest, | ||
setReleaseVersion, | ||
commitReleaseVersion, | ||
tagRelease, | ||
releaseStepCommandAndRemaining("+publishSigned"), | ||
releaseStepCommand("sonatypeBundleRelease"), | ||
setNextVersion, | ||
commitNextVersion, | ||
pushChanges, | ||
), | ||
) | ||
|
||
lazy val releaseSettings = Seq( | ||
scmInfo := Some( | ||
ScmInfo( | ||
url("https://github.com/qwbarch/snowflake4s"), | ||
"scm:git:git@github.com:qwbarch/snowflake4s.git", | ||
), | ||
), | ||
homepage := Some(url("https://github.com/qwbarch/snowflake4s")), | ||
licenses := Seq( | ||
"MIT" -> url("https://opensource.org/licenses/MIT"), | ||
), | ||
pomIncludeRepository := { _ => | ||
false | ||
}, | ||
developers := | ||
List( | ||
Developer( | ||
id = "qwbarch", | ||
name = "qwbarch", | ||
email = "qwbarch@gmail.com", | ||
url = url("https://github.com/qwbarch"), | ||
), | ||
), | ||
publishMavenStyle := true, | ||
Test / publishArtifact := false, | ||
sonatypeCredentialHost := "s01.oss.sonatype.org", | ||
sonatypeRepository := "https://s01.oss.sonatype.org/service/local", | ||
versionScheme := Some("semver-spec"), | ||
releaseCrossBuild := true, | ||
usePgpKeyHex("32C27C5322CC8C7A353D1642E524CDF123A41CB7"), | ||
) | ||
|
||
lazy val sharedPublishSettings = Seq(publishTo := sonatypePublishToBundle.value) | ||
|
||
addCommandAlias("ci", "+undeclaredCompileDependenciesTest; +unusedCompileDependenciesTest; scalafmtCheckAll; +test") |
36 changes: 36 additions & 0 deletions
36
modules/circe/src/main/scala/io/github/qwbarch/snowflake4s/circe/syntax.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) 2021 qwbarch | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package io.github.qwbarch.snowflake4s.circe | ||
|
||
import io.circe.Decoder | ||
import io.circe.Encoder | ||
import io.circe.KeyDecoder | ||
import io.circe.KeyEncoder | ||
import io.github.qwbarch.snowflake4s.Snowflake | ||
|
||
object syntax { | ||
implicit val snowflakeDecoder: Decoder[Snowflake] = Decoder[Long].map(Snowflake.apply) | ||
implicit val snowflakeEncoder: Encoder[Snowflake] = Encoder.encodeLong.contramap(_.value) | ||
|
||
implicit val snowflakeKeyDecoder: KeyDecoder[Snowflake] = KeyDecoder.instance(Snowflake.fromString(_)) | ||
implicit val snowflakeKeyEncoder: KeyEncoder[Snowflake] = KeyEncoder.instance(_.value.toString) | ||
} |
44 changes: 44 additions & 0 deletions
44
modules/circe/src/test/scala/io/github/qwbarch/snowflake4s/circe/CirceSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (c) 2021 qwbarch | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package io.github.qwbarch.snowflake4s.circe | ||
|
||
import weaver.SimpleIOSuite | ||
import weaver.scalacheck.Checkers | ||
import io.circe.syntax._ | ||
import io.github.qwbarch.snowflake4s.arbitrary._ | ||
import io.github.qwbarch.snowflake4s.circe.syntax._ | ||
import io.github.qwbarch.snowflake4s.Snowflake | ||
|
||
object CirceSuite extends SimpleIOSuite with Checkers { | ||
|
||
test("Snowflake serialization") { | ||
forall { (snowflake: Snowflake) => | ||
expect(snowflake.asJson.as[Snowflake].contains(snowflake)) | ||
} | ||
} | ||
|
||
test("Snowflake key serialization") { | ||
forall { (snowflake: Snowflake) => | ||
expect(Map(snowflake -> snowflake).asJson.as[Map[Snowflake, Snowflake]].contains(Map(snowflake -> snowflake))) | ||
} | ||
} | ||
} |
Oops, something went wrong.