Skip to content

Commit 6c0767f

Browse files
authored
Merge branch 'main' into method-names-match-java-sdk
2 parents 5655b45 + b15517f commit 6c0767f

File tree

11 files changed

+64
-57
lines changed

11 files changed

+64
-57
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Setup Java (temurin@8)
4343
id: setup-java-temurin-8
4444
if: matrix.java == 'temurin@8'
45-
uses: actions/setup-java@v3
45+
uses: actions/setup-java@v4
4646
with:
4747
distribution: temurin
4848
java-version: 8
@@ -103,7 +103,7 @@ jobs:
103103
- name: Setup Java (temurin@8)
104104
id: setup-java-temurin-8
105105
if: matrix.java == 'temurin@8'
106-
uses: actions/setup-java@v3
106+
uses: actions/setup-java@v4
107107
with:
108108
distribution: temurin
109109
java-version: 8
@@ -174,7 +174,7 @@ jobs:
174174
- name: Setup Java (temurin@8)
175175
id: setup-java-temurin-8
176176
if: matrix.java == 'temurin@8'
177-
uses: actions/setup-java@v3
177+
uses: actions/setup-java@v4
178178
with:
179179
distribution: temurin
180180
java-version: 8
@@ -195,7 +195,7 @@ jobs:
195195
strategy:
196196
matrix:
197197
os: [ubuntu-latest]
198-
java: [temurin@8]
198+
java: [temurin@11]
199199
runs-on: ${{ matrix.os }}
200200
steps:
201201
- name: Checkout current branch (full)
@@ -206,7 +206,7 @@ jobs:
206206
- name: Setup Java (temurin@8)
207207
id: setup-java-temurin-8
208208
if: matrix.java == 'temurin@8'
209-
uses: actions/setup-java@v3
209+
uses: actions/setup-java@v4
210210
with:
211211
distribution: temurin
212212
java-version: 8
@@ -216,6 +216,19 @@ jobs:
216216
if: matrix.java == 'temurin@8' && steps.setup-java-temurin-8.outputs.cache-hit == 'false'
217217
run: sbt +update
218218

219+
- name: Setup Java (temurin@11)
220+
id: setup-java-temurin-11
221+
if: matrix.java == 'temurin@11'
222+
uses: actions/setup-java@v4
223+
with:
224+
distribution: temurin
225+
java-version: 11
226+
cache: sbt
227+
228+
- name: sbt update
229+
if: matrix.java == 'temurin@11' && steps.setup-java-temurin-11.outputs.cache-hit == 'false'
230+
run: sbt +update
231+
219232
- name: Generate site
220233
run: sbt docs/tlSite
221234

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = 3.7.15
1+
version = 3.8.0
22

33
style = default
44

CODE_OF_CONDUCT.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,33 @@ A thin wrapper for the [Launch Darkly Java server SDK](https://github.com/launch
1515
val sdkKey = "my-sdk-key"
1616
val config: LDConfig = new LDConfig.Builder().build()
1717
val launchDarklyClientResource: Resource[IO, LaunchDarklyClient[IO]] = LaunchDarklyClient.resource[IO](sdkKey, config)
18-
18+
1919
override def run: IO[Unit] = launchDarklyClientResource.use { client =>
2020
for {
2121
// Boolean Variant
22-
bool <- client.boolVariation[LDUser]("BOOL-FLAG", new LDUser("user-identifier"), defaultValue = false)
22+
bool <- client.boolVariation("BOOL-FLAG", new LDContext("context-name"), defaultValue = false)
2323
_ <- IO.println(s"Boolean Variation: ${bool}")
24-
24+
2525
// String Variant
26-
string <- client.stringVariation[LDUser]("STRING-FLAG", new LDUser("user-identifier"), defaultValue = "default-string")
26+
string <- client.stringVariation("STRING-FLAG", new LDContext("context-name"), defaultValue = "default-string")
2727
_ <- IO.println(s"String Variation: ${string}")
28-
28+
2929
// Integer Variant
30-
int <- client.intVariation[LDUser]("INTEGER-FLAG", new LDUser("user-identifier"), defaultValue = 0)
30+
int <- client.intVariation("INTEGER-FLAG", new LDContext("context-name"), defaultValue = 0)
3131
_ <- IO.println(s"Integer Variation: ${int}")
32-
32+
3333
// Double Variant
34-
double <- client.doubleVariation[LDUser]("DOUBLE-FLAG", new LDUser("user-identifier"), defaultValue = 0.00D)
34+
double <- client.doubleVariation("DOUBLE-FLAG", new LDContext("context-name"), defaultValue = 0.00D)
3535
_ <- IO.println(s"Double Variation: ${double}")
36-
36+
3737
// JSON Variant
38-
json <- client.jsonValueVariation[LDUser]("JSON-FLAG", new LDUser("user-identifier"), defaultValue = LDValue.of("{}"))
38+
json <- client.jsonValueVariation("JSON-FLAG", new LDContext("context-name"), defaultValue = LDValue.of("{}"))
3939
_ <- IO.println(s"JSON Variation: ${json}")
4040
} yield ()
4141
}
4242
}
4343
```
4444

45-
### LDUser versus LDContext
46-
47-
From the LaunchDarkly [documentation](https://javadoc.io/doc/com.launchdarkly/launchdarkly-java-server-sdk/latest/com/launchdarkly/sdk/LDContext.html):
48-
49-
> LDContext is the newer replacement for the previous, less flexible LDUser type. The current LaunchDarkly SDK still supports LDUser, but
50-
LDContext is now the preferred model and may entirely replace LDUser in the future.
51-
52-
A typeclass exists within Catapult for converting between `LDUser` and `LDContext`, so the variation methods can be called using either, hence the typed variation methods.
53-
5445
### Flush the buffered event queue
5546

5647
Specifies that any buffered events should be sent as soon as possible, rather than waiting for the next flush interval.

build.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ThisBuild / tlSonatypeUseLegacyHost := false
1818
ThisBuild / tlSitePublishBranch := Some("main")
1919

2020
val Scala213 = "2.13.12"
21-
ThisBuild / crossScalaVersions := Seq(Scala213, "3.3.1")
21+
ThisBuild / crossScalaVersions := Seq(Scala213, "3.3.3")
2222
ThisBuild / scalaVersion := Scala213 // the default Scala
2323

2424
lazy val root = tlCrossRootProject.aggregate(core, testkit)
@@ -44,8 +44,8 @@ lazy val core = crossProject(JVMPlatform)
4444
libraryDependencies ++= Seq(
4545
"org.typelevel" %%% "cats-core" % "2.10.0",
4646
"org.typelevel" %%% "cats-effect" % "3.5.2",
47-
"co.fs2" %%% "fs2-core" % "3.9.2",
48-
"com.launchdarkly" % "launchdarkly-java-server-sdk" % "6.2.1",
47+
"co.fs2" %%% "fs2-core" % "3.9.4",
48+
"com.launchdarkly" % "launchdarkly-java-server-sdk" % "7.1.1",
4949
),
5050
)
5151

core/src/main/scala/org.typelevel/catapult/ContextEncoder.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ object ContextEncoder {
4141

4242
implicit val catapultContextEncoderForLdContext: ContextEncoder[LDContext] = identity(_)
4343

44+
@deprecated("Use LDContext instead of LDUser", "0.5.0")
4445
implicit val catapultContextEncoderForLdUser: ContextEncoder[LDUser] = LDContext.fromUser(_)
4546
}

core/src/main/scala/org.typelevel/catapult/LaunchDarklyClient.scala

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,29 @@ trait LaunchDarklyClient[F[_]] {
119119
}
120120

121121
object LaunchDarklyClient {
122+
123+
/** @return a Catapult [[LaunchDarklyClient]] wrapped in [[cats.effect.Resource]], created using the given SDK key and config
124+
*/
122125
def resource[F[_]](sdkKey: String, config: LDConfig)(implicit
123126
F: Async[F]
124127
): Resource[F, LaunchDarklyClient[F]] =
125128
Resource
126129
.fromAutoCloseable(F.blocking(new LDClient(sdkKey, config)))
127-
.map(ldClient => defaultLaunchDarklyClient(ldClient))
130+
.map(ldClient => unsafeFromJava(ldClient))
128131

132+
/** @return a Catapult [[LaunchDarklyClient]] wrapped in [[cats.effect.Resource]], created using the given SDK key and default config
133+
*/
129134
def resource[F[_]](sdkKey: String)(implicit F: Async[F]): Resource[F, LaunchDarklyClient[F]] =
130135
Resource
131136
.fromAutoCloseable(F.blocking(new LDClient(sdkKey)))
132-
.map(ldClient => defaultLaunchDarklyClient(ldClient))
137+
.map(ldClient => unsafeFromJava(ldClient))
133138

134-
private def defaultLaunchDarklyClient[F[_]](
139+
/** @return a Catapult [[LaunchDarklyClient]] created using the provided `LDClient`.
140+
* It is the caller's responsibility to close the underlying `LDClient`.
141+
*/
142+
def unsafeFromJava[F[_]](
135143
ldClient: LDClient
136-
)(implicit F: Async[F]): LaunchDarklyClient.Default[F] =
144+
)(implicit F: Async[F]): LaunchDarklyClient[F] =
137145
new LaunchDarklyClient.Default[F] {
138146

139147
override def unsafeWithJavaClient[A](f: LDClient => A): F[A] =
@@ -166,7 +174,7 @@ object LaunchDarklyClient {
166174
}
167175
}
168176

169-
trait Default[F[_]] extends LaunchDarklyClient[F] {
177+
private trait Default[F[_]] extends LaunchDarklyClient[F] {
170178
self =>
171179
protected def unsafeWithJavaClient[A](f: LDClient => A): F[A]
172180

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.9.7
1+
sbt.version=1.9.8

project/plugins.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.6.1")
2-
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.6.1")
3-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.14.0")
1+
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.6.4")
2+
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.6.4")
3+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.15.0")

testkit/src/main/scala/org/typelevel/catapult/testkit/package.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@
1717
package org.typelevel.catapult
1818

1919
import cats.effect.{Async, Resource}
20-
import cats.syntax.all._
21-
import com.launchdarkly.sdk.server.LDConfig
20+
import cats.syntax.all.*
21+
import com.launchdarkly.sdk.server.{Components, LDConfig}
2222
import com.launchdarkly.sdk.server.integrations.TestData
2323

2424
package object testkit {
2525
def testClient[F[_]](implicit F: Async[F]): Resource[F, (TestData, LaunchDarklyClient[F])] =
2626
Resource.eval(F.delay(TestData.dataSource())).flatMap { td =>
2727
LaunchDarklyClient
28-
.resource("fake-key", new LDConfig.Builder().dataSource(td).build)
28+
.resource(
29+
"fake-key",
30+
new LDConfig.Builder()
31+
.dataSource(td)
32+
.events(
33+
Components.noEvents() // prevent client from attempting to send events to LD servers
34+
)
35+
.build,
36+
)
2937
.tupleLeft(td)
3038
}
3139
}

0 commit comments

Comments
 (0)