Skip to content

Commit

Permalink
Merge branch 'main' of github.com:typelevel/skunk into add-alter-inde…
Browse files Browse the repository at this point in the history
…x-completion
  • Loading branch information
jachro committed Oct 20, 2023
2 parents 345a23c + c0303dd commit 560ee69
Show file tree
Hide file tree
Showing 31 changed files with 305 additions and 236 deletions.
245 changes: 117 additions & 128 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version = "3.7.9"
version = "3.7.14"
runner.dialect = Scala213Source3
project.includePaths = [] # disables formatting
59 changes: 32 additions & 27 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ThisBuild / tlBaseVersion := "1.0"

// Our Scala versions.
lazy val `scala-2.13` = "2.13.10"
lazy val `scala-3` = "3.3.0"
lazy val `scala-2.13` = "2.13.12"
lazy val `scala-3` = "3.3.1"

ThisBuild / scalaVersion := `scala-2.13`
ThisBuild / crossScalaVersions := Seq(`scala-2.13`, `scala-3`)
Expand All @@ -14,14 +14,15 @@ ThisBuild / developers := List(
)

ThisBuild / tlCiReleaseBranches += "series/0.6.x"
ThisBuild / tlCiScalafmtCheck := false
ThisBuild / tlSitePublishBranch := Some("series/0.6.x")
ThisBuild / tlSonatypeUseLegacyHost := false
ThisBuild / githubWorkflowOSes := Seq("ubuntu-latest")
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("11"))
ThisBuild / tlJdkRelease := Some(8)

ThisBuild / githubWorkflowBuildPreamble ++= nativeBrewInstallWorkflowSteps.value
ThisBuild / nativeBrewInstallCond := Some("matrix.project == 'rootNative'")
ThisBuild / nativeBrewInstallCond := Some("matrix.project == 'skunkNative'")

lazy val setupCertAndDocker = Seq(
WorkflowStep.Run(
Expand All @@ -36,15 +37,12 @@ ThisBuild / tlCiHeaderCheck := true
ThisBuild / githubWorkflowAddedJobs +=
WorkflowJob(
id = "coverage",
name = s"Generate coverage report (${`scala-2.13`} JVM only)",
name = s"Generate coverage report (2.13 JVM only)",
scalas = List(`scala-2.13`),
steps = githubWorkflowJobSetup.value.toList ++
List(
WorkflowStep.Sbt(List("coverage", "rootJVM/test", "coverageReport")),
WorkflowStep.Run(
List("bash <(curl -s https://codecov.io/bash)"),
name = Some("Upload code coverage data")
)
WorkflowStep.Sbt(List("coverage", "skunkJVM/test", "coverageReport")),
WorkflowStep.Use(UseRef.Public("codecov", "codecov-action", "v3"))
)
)

Expand All @@ -59,9 +57,9 @@ ThisBuild / mimaBinaryIssueFilters ++= List(
)

// This is used in a couple places
lazy val fs2Version = "3.7.0"
lazy val openTelemetryVersion = "1.28.0"
lazy val otel4sVersion = "0.2.1"
lazy val fs2Version = "3.9.2"
lazy val openTelemetryVersion = "1.29.0"
lazy val otel4sVersion = "0.3.0-RC1"

// Global Settings
lazy val commonSettings = Seq(
Expand All @@ -82,7 +80,7 @@ lazy val commonSettings = Seq(

// Compilation
scalacOptions -= "-language:experimental.macros", // doesn't work cross-version
Compile / doc / scalacOptions --= Seq("-Xfatal-warnings"),
Compile / doc / scalacOptions --= Seq("-Werror"),
Compile / doc / scalacOptions ++= Seq(
"-groups",
"-sourcepath", (LocalRootProject / baseDirectory).value.getAbsolutePath,
Expand All @@ -109,10 +107,9 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.settings(
name := "skunk-core",
description := "Tagless, non-blocking data access library for Postgres.",
scalacOptions ~= (_.filterNot(_ == "-source:3.0-migration")),
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "2.9.0",
"org.typelevel" %%% "cats-effect" % "3.5.0",
"org.typelevel" %%% "cats-core" % "2.10.0",
"org.typelevel" %%% "cats-effect" % "3.5.2",
"co.fs2" %%% "fs2-core" % fs2Version,
"co.fs2" %%% "fs2-io" % fs2Version,
"org.scodec" %%% "scodec-bits" % "1.1.37",
Expand All @@ -122,7 +119,7 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
"org.tpolecat" %%% "sourcepos" % "1.1.0",
"org.typelevel" %%% "twiddles-core" % "0.6.0",
) ++ Seq(
"com.beachape" %%% "enumeratum" % "1.7.2",
"com.beachape" %%% "enumeratum" % "1.7.3",
).filterNot(_ => tlIsScala3.value)
).jvmSettings(
libraryDependencies += "com.ongres.scram" % "client" % "2.1",
Expand All @@ -143,7 +140,7 @@ lazy val refined = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.settings(
name := "skunk-refined",
libraryDependencies ++= Seq(
"eu.timepit" %%% "refined" % "0.10.3",
"eu.timepit" %%% "refined" % "0.11.0",
)
)

Expand All @@ -156,28 +153,29 @@ lazy val circe = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.settings(
name := "skunk-circe",
libraryDependencies ++= Seq(
"io.circe" %%% "circe-core" % "0.14.5",
"io.circe" %%% "circe-parser" % "0.14.5"
"io.circe" %%% "circe-core" % "0.14.6",
"io.circe" %%% "circe-parser" % "0.14.6"
)
)

lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("modules/tests"))
.dependsOn(core, circe)
.dependsOn(core, circe, refined)
.enablePlugins(AutomateHeaderPlugin, NoPublishPlugin)
.settings(commonSettings)
.settings(
scalacOptions -= "-Xfatal-warnings",
tlFatalWarnings := false,
libraryDependencies ++= Seq(
"org.scalameta" %%% "munit" % "1.0.0-M7",
"org.scalameta" % "junit-interface" % "1.0.0-M7",
"org.scalameta" %%% "munit" % "1.0.0-M10",
"org.scalameta" % "junit-interface" % "1.0.0-M10",
"org.typelevel" %%% "scalacheck-effect-munit" % "2.0.0-M2",
"org.typelevel" %%% "munit-cats-effect" % "2.0.0-M3",
"org.typelevel" %%% "cats-free" % "2.9.0",
"org.typelevel" %%% "cats-laws" % "2.9.0",
"org.typelevel" %%% "cats-free" % "2.10.0",
"org.typelevel" %%% "cats-laws" % "2.10.0",
"org.typelevel" %%% "discipline-munit" % "2.0.0-M3",
"org.typelevel" %%% "cats-time" % "0.5.1",
"eu.timepit" %%% "refined-cats" % "0.10.3",
),
testFrameworks += new TestFramework("munit.Framework"),
testOptions += {
Expand All @@ -204,7 +202,7 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
)
.nativeEnablePlugins(ScalaNativeBrewedConfigPlugin)
.nativeSettings(
libraryDependencies += "com.armanbilge" %%% "epollcat" % "0.1.4",
libraryDependencies += "com.armanbilge" %%% "epollcat" % "0.1.6",
Test / nativeBrewFormulas ++= Set("s2n", "utf8proc"),
Test / envVars ++= Map("S2N_DONT_MLOCK" -> "1")
)
Expand Down Expand Up @@ -246,7 +244,14 @@ lazy val docs = project
.enablePlugins(TypelevelSitePlugin)
.settings(commonSettings)
.settings(
scalacOptions ~= {
_.map {
case opt if opt.startsWith("-Xlint") => s"$opt,-missing-interpolator"
case opt => opt
}
},
mdocIn := (Compile / sourceDirectory).value / "laika",
tlSiteIsTypelevelProject := Some(TypelevelProject.Affiliate),
laikaConfig := {
import laika.rewrite.link._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ private[message] trait PasswordMessagePlatform {
// First round
if (EVP_DigestInit_ex(ctx, `type`, null) != 1)
throw new RuntimeException("EVP_DigestInit_ex")
if (EVP_DigestUpdate(ctx, password.getBytes.at(0), password.length.toULong) != 1)
if (EVP_DigestUpdate(ctx, password.getBytes.atUnsafe(0), password.length.toULong) != 1)
throw new RuntimeException("EVP_DigestUpdate")
if (EVP_DigestUpdate(ctx, user.getBytes.at(0), user.length.toULong) != 1)
if (EVP_DigestUpdate(ctx, user.getBytes.atUnsafe(0), user.length.toULong) != 1)
throw new RuntimeException("EVP_DigestUpdate")
if (EVP_DigestFinal_ex(ctx, md.at(0), size) != 1)
if (EVP_DigestFinal_ex(ctx, md.atUnsafe(0), size) != 1)
throw new RuntimeException("EVP_DigestFinal_ex")
var hex = BigInt(1, md.take((!size).toInt)).toString(16)
while (hex.length < 32)
Expand All @@ -48,11 +48,11 @@ private[message] trait PasswordMessagePlatform {
// Second round
if (EVP_DigestInit_ex(ctx, `type`, null) != 1)
throw new RuntimeException("EVP_DigestInit_ex")
if (EVP_DigestUpdate(ctx, hex.getBytes.at(0), 32.toULong) != 1)
if (EVP_DigestUpdate(ctx, hex.getBytes.atUnsafe(0), 32.toULong) != 1)
throw new RuntimeException("EVP_DigestUpdate")
if (EVP_DigestUpdate(ctx, salt.at(0), salt.length.toULong) != 1)
if (EVP_DigestUpdate(ctx, salt.atUnsafe(0), salt.length.toULong) != 1)
throw new RuntimeException("EVP_DigestUpdate")
if (EVP_DigestFinal_ex(ctx, md.at(0), size) != 1)
if (EVP_DigestFinal_ex(ctx, md.atUnsafe(0), size) != 1)
throw new RuntimeException("EVP_DigestFinal_ex")
hex = BigInt(1, md.take((!size).toInt)).toString(16)
while (hex.length < 32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private[message] trait ScramPlatform { this: Scram.type =>

def clientFirstBareWithRandomNonce: ByteVector = {
val buf = new Array[Byte](32)
if (RAND_bytes(buf.at(0), 32) != 1)
if (RAND_bytes(buf.atUnsafe(0), 32) != 1)
throw new RuntimeException("RAND_bytes")
val nonce = ByteVector.view(buf).toBase64
clientFirstBareWithNonce(nonce)
Expand All @@ -27,7 +27,7 @@ private[message] trait ScramPlatform { this: Scram.type =>
throw new RuntimeException("EVP_get_digestbyname")
val md = new Array[Byte](EVP_MAX_MD_SIZE)
val mdLen = stackalloc[CUnsignedInt]()
if (openssl.HMAC(evpMd, key.toArrayUnsafe.at(0), key.size.toInt, str.toArrayUnsafe.at(0), str.size.toULong, md.at(0), mdLen) == null)
if (openssl.HMAC(evpMd, key.toArrayUnsafe.atUnsafe(0), key.size.toInt, str.toArrayUnsafe.atUnsafe(0), str.size.toULong, md.atUnsafe(0), mdLen) == null)
throw new RuntimeException("HMAC")
ByteVector.view(md, 0, (!mdLen).toInt)
}
Expand All @@ -38,7 +38,7 @@ private[message] trait ScramPlatform { this: Scram.type =>
val `type` = EVP_get_digestbyname(c"SHA256")
if (`type` == null)
throw new RuntimeException("EVP_get_digestbyname")
if (EVP_Digest(input.toArrayUnsafe.at(0), input.size.toULong, md.at(0), size, `type`, null) != 1)
if (EVP_Digest(input.toArrayUnsafe.atUnsafe(0), input.size.toULong, md.atUnsafe(0), size, `type`, null) != 1)
throw new RuntimeException("EVP_Digest")
ByteVector.view(md, 0, (!size).toInt)
}
Expand All @@ -48,7 +48,7 @@ private[message] trait ScramPlatform { this: Scram.type =>
if (digest == null)
throw new RuntimeException("EVP_get_digestbyname")
val out = new Array[Byte](32)
if (PKCS5_PBKDF2_HMAC(str.getBytes.at(0), str.length, salt.toArrayUnsafe.at(0), salt.size.toInt, iterations, digest, 32, out.at(0)) != 1)
if (PKCS5_PBKDF2_HMAC(str.getBytes.atUnsafe(0), str.length, salt.toArrayUnsafe.atUnsafe(0), salt.size.toInt, iterations, digest, 32, out.atUnsafe(0)) != 1)
throw new RuntimeException("PKCS5_PBKDF2_HMAC")
ByteVector.view(out)
}
Expand Down
3 changes: 3 additions & 0 deletions modules/core/native/src/main/scala/net/message/openssl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

package skunk.net.message

import org.typelevel.scalaccompat.annotation._

import scala.scalanative.unsafe._

@nowarn212
@link("crypto")
@extern
private[message] object openssl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ object StringContextOps {
}

def identifier_impl(): Tree = {
val Apply(_, List(Apply(_, List(Literal(Constant(part: String)))))) = c.prefix.tree
val Apply(_, List(Apply(_, List(Literal(Constant(part: String)))))) = c.prefix.tree: @unchecked
Identifier.fromString(part) match {
case Left(s) => c.abort(c.enclosingPosition, s)
case Right(Identifier(s)) => q"_root_.skunk.data.Identifier.fromString($s).fold(sys.error, identity)"
Expand Down
1 change: 0 additions & 1 deletion modules/core/shared/src/main/scala-3/SqlState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package skunk

import scala.collection.immutable.IndexedSeq
import skunk.exception.PostgresErrorException

/**
Expand Down
1 change: 0 additions & 1 deletion modules/core/shared/src/main/scala-3/util/Twiddler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package skunk
package util

import scala.annotation.implicitNotFound
import scala.quoted._
import scala.deriving.Mirror

import skunk.implicits._
Expand Down
2 changes: 1 addition & 1 deletion modules/core/shared/src/main/scala/PreparedQuery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ object PreparedQuery {
Stream.resource(proto.bind(args, or)).flatMap { cursor =>
def chunks: Stream[F, B] =
Stream.eval(cursor.execute(chunkSize)).flatMap { case (bs, more) =>
val s = Stream.chunk(Chunk.seq(bs))
val s = Stream.chunk(Chunk.from(bs))
if (more) s ++ chunks
else s
}
Expand Down
3 changes: 1 addition & 2 deletions modules/core/shared/src/main/scala/codec/BinaryCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ trait BinaryCodecs {
def bit(length: Int): Codec[BitVector] =
Codec.simple[BitVector](
_.toBin,
s => { println(s"got $s"); BitVector.fromBinDescriptive(s) },
// BitVector.fromBinDescriptive(_),
BitVector.fromBinDescriptive(_),
Type.bit(length)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ trait TemporalCodecs {
.optionalStart
.appendFraction(NANO_OF_SECOND, 0, precision, true)
.optionalEnd
()
}

requiredPart.toFormatter(Locale.US)
Expand Down
4 changes: 2 additions & 2 deletions modules/core/shared/src/main/scala/data/Arr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ final class Arr[A] private (
) {

// Data and extent must be consistent. Should be guaranteed but let's check anyway.
assert((data.isEmpty && extent.isEmpty) || (data.length == extent.product))
assert((data.isEmpty && extent.isEmpty) || (data.length == wrapIntArray(extent).product))

// In order to access elements we need the offsets associated with each dimension. But let's not
// compute it unless we need to since these will be constructed in a tight loop when we unroll
// a resultset that contains array columns.
private lazy val _offsets: Array[Int] =
extent.tails.map(_.product).drop(1).toArray
extent.tails.map(wrapIntArray(_).product).drop(1).toArray

/**
* Attempt to reshape this `Arr` with the specified dimensions. This is possible if and only if
Expand Down
2 changes: 2 additions & 0 deletions modules/core/shared/src/main/scala/data/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ object Completion {
case object DropTrigger extends Completion
case object SetConstraints extends Completion
case object Explain extends Completion
case object Grant extends Completion
case object Revoke extends Completion
case object AlterIndex extends Completion
// more ...

Expand Down
1 change: 0 additions & 1 deletion modules/core/shared/src/main/scala/net/message/Bind.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package skunk.net.message

import cats.syntax.all._
import scodec.interop.cats._
import scodec._
import scodec.codecs._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ object CommandComplete {
case Patterns.Copy(s) => apply(Completion.Copy(s.toInt))
case "SET CONSTRAINTS" => apply(Completion.SetConstraints)
case "EXPLAIN" => apply(Completion.Explain)
case "GRANT" => apply(Completion.Grant)
case "REVOKE" => apply(Completion.Revoke)
case "ALTER INDEX" => apply(Completion.AlterIndex)
// more .. fill in as we hit them

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package skunk.net.message

import cats.syntax.all._
import scodec.interop.cats._
import scodec.codecs._
import scodec.Encoder

Expand Down
1 change: 0 additions & 1 deletion modules/core/shared/src/main/scala/net/message/Parse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package skunk.net.message

import cats.syntax.all._
import scodec.interop.cats._
import scodec.codecs._
import scodec.Encoder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package skunk.net.message

import cats.syntax.all._
import scodec.interop.cats._
import scodec.Encoder
import scodec.bits.ByteVector
import scodec.codecs.{bytes, int32, variableSizeBytes}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package skunk.net.message

import cats.syntax.all._
import scodec.interop.cats._
import scodec._
import scodec.codecs._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package protocol
import cats.FlatMap
import cats.syntax.all._
import skunk.net.message.{ Close => CloseMessage, Flush, CloseComplete }
import skunk.net.MessageSocket
import org.typelevel.otel4s.Attribute
import org.typelevel.otel4s.trace.Span
import org.typelevel.otel4s.trace.Tracer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object Parse {
_ <- span.addAttributes(
Attribute("statement-name", id.value),
Attribute("statement-sql", statement.sql),
Attribute("statement-parameter-types", os.map(n => ty.typeForOid(n, -1).getOrElse(n)).mkString("[", ", ", "]"))
Attribute("statement-parameter-types", os.map(n => ty.typeForOid(n, -1).fold(n.toString)(_.toString)).mkString("[", ", ", "]"))
)
_ <- send(ParseMessage(id.value, statement.sql, os))
_ <- send(Flush)
Expand Down
Loading

0 comments on commit 560ee69

Please sign in to comment.