Skip to content

Commit

Permalink
Merge pull request #8 from bplommer/bump-ld-sdk
Browse files Browse the repository at this point in the history
Bump dependencies
  • Loading branch information
bplommer authored Mar 27, 2023
2 parents 2538aac + 620a9f8 commit 53aae59
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 43 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.8, 3.1.1]
scala: [2.13.10, 3.2.2]
java: [temurin@8]
project: [rootJVM]
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.8]
scala: [2.13.10]
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -143,22 +143,22 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.13.8, rootJVM)
- name: Download target directories (2.13.10, rootJVM)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.8-rootJVM
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-rootJVM

- name: Inflate target directories (2.13.8, rootJVM)
- name: Inflate target directories (2.13.10, rootJVM)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.1, rootJVM)
- name: Download target directories (3.2.2, rootJVM)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.1.1-rootJVM
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.2-rootJVM

- name: Inflate target directories (3.1.1, rootJVM)
- name: Inflate target directories (3.2.2, rootJVM)
run: |
tar xf targets.tar
rm targets.tar
Expand All @@ -182,7 +182,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.8]
scala: [2.13.10]
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
Expand Down
16 changes: 8 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://typelevel.org/sbt-typelevel/faq.html#what-is-a-base-version-anyway
ThisBuild / tlBaseVersion := "0.2" // your current series x.y
ThisBuild / tlBaseVersion := "0.3" // your current series x.y

ThisBuild / organization := "io.github.bplommer"
ThisBuild / organizationName := "Ben Plommer"
Expand All @@ -16,8 +16,8 @@ ThisBuild / tlSonatypeUseLegacyHost := false
// publish website from this branch
ThisBuild / tlSitePublishBranch := Some("main")

val Scala213 = "2.13.8"
ThisBuild / crossScalaVersions := Seq(Scala213, "3.1.1")
val Scala213 = "2.13.10"
ThisBuild / crossScalaVersions := Seq(Scala213, "3.2.2")
ThisBuild / scalaVersion := Scala213 // the default Scala

lazy val root = tlCrossRootProject.aggregate(core, testkit)
Expand All @@ -28,7 +28,7 @@ lazy val testkit = crossProject(JVMPlatform)
.settings(
name := "catapult-testkit",
libraryDependencies ++= Seq(
"com.disneystreaming" %% "weaver-cats" % "0.7.12" % Test
"com.disneystreaming" %% "weaver-cats" % "0.8.1" % Test
),
testFrameworks += new TestFramework("weaver.framework.CatsEffect"),
tlVersionIntroduced := List("2.13", "3").map(_ -> "0.1.0").toMap,
Expand All @@ -41,10 +41,10 @@ lazy val core = crossProject(JVMPlatform)
.settings(
name := "catapult",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "2.8.0",
"org.typelevel" %%% "cats-effect" % "3.3.14",
"co.fs2" %%% "fs2-core" % "3.3.0",
"com.launchdarkly" % "launchdarkly-java-server-sdk" % "5.10.3",
"org.typelevel" %%% "cats-core" % "2.9.0",
"org.typelevel" %%% "cats-effect" % "3.4.8",
"co.fs2" %%% "fs2-core" % "3.6.1",
"com.launchdarkly" % "launchdarkly-java-server-sdk" % "6.0.6",
),
)

Expand Down
90 changes: 64 additions & 26 deletions core/src/main/scala/catapult/LaunchDarklyClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,40 @@ import cats.effect.{Async, Resource}
import cats.~>
import com.launchdarkly.sdk.server.interfaces.{FlagValueChangeEvent, FlagValueChangeListener}
import com.launchdarkly.sdk.server.{LDClient, LDConfig}
import com.launchdarkly.sdk.{LDUser, LDValue}
import com.launchdarkly.sdk.{LDContext, LDUser, LDValue}
import fs2._

trait LaunchDarklyClient[F[_]] {
def boolVariation(featureKey: String, user: LDUser, defaultValue: Boolean): F[Boolean]

def stringVariation(featureKey: String, user: LDUser, defaultValue: String): F[String]
def boolVariation(featureKey: String, context: LDContext, defaultValue: Boolean): F[Boolean]

def intVariation(featureKey: String, user: LDUser, defaultValue: Int): F[Int]
final def boolVariation(featureKey: String, user: LDUser, defaultValue: Boolean): F[Boolean] =
boolVariation(featureKey, LDContext.fromUser(user), defaultValue)

def doubleVariation(featureKey: String, user: LDUser, defaultValue: Double): F[Double]
def stringVariation(featureKey: String, context: LDContext, defaultValue: String): F[String]

def jsonVariation(featureKey: String, user: LDUser, defaultValue: LDValue): F[LDValue]
final def stringVariation(featureKey: String, user: LDUser, defaultValue: String): F[String] =
stringVariation(featureKey, LDContext.fromUser(user), defaultValue)

def listen(featureKey: String, user: LDUser): Stream[F, FlagValueChangeEvent]
def intVariation(featureKey: String, context: LDContext, defaultValue: Int): F[Int]

final def intVariation(featureKey: String, user: LDUser, defaultValue: Int): F[Int] =
intVariation(featureKey, LDContext.fromUser(user), defaultValue)

def doubleVariation(featureKey: String, context: LDContext, defaultValue: Double): F[Double]

final def doubleVariation(featureKey: String, user: LDUser, defaultValue: Double): F[Double] =
doubleVariation(featureKey, LDContext.fromUser(user), defaultValue)

def jsonVariation(featureKey: String, context: LDContext, defaultValue: LDValue): F[LDValue]

final def jsonVariation(featureKey: String, user: LDUser, defaultValue: LDValue): F[LDValue] =
jsonVariation(featureKey, LDContext.fromUser(user), defaultValue)

def listen(featureKey: String, context: LDContext): Stream[F, FlagValueChangeEvent]

final def listen(featureKey: String, user: LDUser): Stream[F, FlagValueChangeEvent] =
listen(featureKey, LDContext.fromUser(user))

def flush: F[Unit]

Expand All @@ -54,17 +73,20 @@ object LaunchDarklyClient {
override def unsafeWithJavaClient[A](f: LDClient => A): F[A] =
F.blocking(f(ldClient))

override def listen(featureKey: String, user: LDUser): Stream[F, FlagValueChangeEvent] =
override def listen(
featureKey: String,
context: LDContext,
): Stream[F, FlagValueChangeEvent] =
Stream.eval(F.delay(ldClient.getFlagTracker)).flatMap { tracker =>
Stream.resource(Dispatcher[F]).flatMap { dispatcher =>
Stream.resource(Dispatcher.sequential[F]).flatMap { dispatcher =>
Stream.eval(Queue.unbounded[F, FlagValueChangeEvent]).flatMap { q =>
val listener = new FlagValueChangeListener {
override def onFlagValueChange(event: FlagValueChangeEvent): Unit =
dispatcher.unsafeRunSync(q.offer(event))
}

Stream.bracket(
F.delay(tracker.addFlagValueChangeListener(featureKey, user, listener))
F.delay(tracker.addFlagValueChangeListener(featureKey, context, listener))
)(listener => F.delay(tracker.removeFlagChangeListener(listener))) >>
Stream.fromQueueUnterminated(q)
}
Expand All @@ -77,20 +99,36 @@ object LaunchDarklyClient {
self =>
protected def unsafeWithJavaClient[A](f: LDClient => A): F[A]

override def boolVariation(featureKey: String, user: LDUser, default: Boolean): F[Boolean] =
unsafeWithJavaClient(_.boolVariation(featureKey, user, default))

override def stringVariation(featureKey: String, user: LDUser, default: String): F[String] =
unsafeWithJavaClient(_.stringVariation(featureKey, user, default))

override def intVariation(featureKey: String, user: LDUser, default: Int): F[Int] =
unsafeWithJavaClient(_.intVariation(featureKey, user, default))

override def doubleVariation(featureKey: String, user: LDUser, default: Double): F[Double] =
unsafeWithJavaClient(_.doubleVariation(featureKey, user, default))

override def jsonVariation(featureKey: String, user: LDUser, default: LDValue): F[LDValue] =
unsafeWithJavaClient(_.jsonValueVariation(featureKey, user, default))
override def boolVariation(
featureKey: String,
context: LDContext,
default: Boolean,
): F[Boolean] =
unsafeWithJavaClient(_.boolVariation(featureKey, context, default))

override def stringVariation(
featureKey: String,
context: LDContext,
default: String,
): F[String] =
unsafeWithJavaClient(_.stringVariation(featureKey, context, default))

override def intVariation(featureKey: String, context: LDContext, default: Int): F[Int] =
unsafeWithJavaClient(_.intVariation(featureKey, context, default))

override def doubleVariation(
featureKey: String,
context: LDContext,
default: Double,
): F[Double] =
unsafeWithJavaClient(_.doubleVariation(featureKey, context, default))

override def jsonVariation(
featureKey: String,
context: LDContext,
default: LDValue,
): F[LDValue] =
unsafeWithJavaClient(_.jsonValueVariation(featureKey, context, default))

override def flush: F[Unit] = unsafeWithJavaClient(_.flush())

Expand All @@ -99,8 +137,8 @@ object LaunchDarklyClient {
self.unsafeWithJavaClient(f)
)

override def listen(featureKey: String, user: LDUser): Stream[G, FlagValueChangeEvent] =
self.listen(featureKey, user).translate(fk)
override def listen(featureKey: String, context: LDContext): Stream[G, FlagValueChangeEvent] =
self.listen(featureKey, context).translate(fk)

override def flush: G[Unit] = fk(self.flush)
}
Expand Down

0 comments on commit 53aae59

Please sign in to comment.