Skip to content

Commit a5fe67b

Browse files
authored
Merge pull request #192 from powersync-ja/rust-sync-client
Add sync implementation from core extension
2 parents e6bde1b + 0eed4e4 commit a5fe67b

File tree

42 files changed

+1238
-506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1238
-506
lines changed

CHANGELOG.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
11
# Changelog
22

3-
## 1.1.2 (pending)
4-
3+
## 1.2.0 (pending)
4+
5+
* Add a new sync client implementation written in Rust instead of Kotlin. While this client is still
6+
experimental, we intend to make it the default in the future. The main benefit of this client is
7+
faster sync performance, but upcoming features will also require this client. We encourage
8+
interested users to try it out by opting in to `ExperimentalPowerSyncAPI` and passing options when
9+
connecting:
10+
```Kotlin
11+
//@file:OptIn(ExperimentalPowerSyncAPI::class)
12+
database.connect(MyConnector(), options = SyncOptions(
13+
newClientImplementation = true,
14+
))
15+
```
16+
Switching between the clients can be done at any time without compatibility issues. If you run
17+
into issues with the new client, please reach out to us!
18+
* In addition to HTTP streams, the Kotlin SDK also supports fetching sync instructions from the
19+
PowerSync service in a binary format. This requires the new sync client, and can then be enabled
20+
on the sync options:
21+
```Kotlin
22+
//@file:OptIn(ExperimentalPowerSyncAPI::class)
23+
database.connect(MyConnector(), options = SyncOptions(
24+
newClientImplementation = true,
25+
method = ConnectionMethod.WebSocket()
26+
))
27+
```
528
* [Android, JVM] Use version `0.4.0` of `powersync-sqlite-core`.
629

730
## 1.1.1

PowerSyncKotlin/src/appleMain/kotlin/com/powersync/SDK.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
package com.powersync
44

5+
import com.powersync.sync.ConnectionMethod
6+
import com.powersync.sync.SyncOptions
7+
58
/**
69
* Helper class designed to bridge SKIEE methods and allow them to throw
710
* `PowerSyncException`. This is necessary because these exceptions cannot
@@ -13,3 +16,25 @@ package com.powersync
1316
*/
1417
@Throws(PowerSyncException::class)
1518
public fun throwPowerSyncException(exception: PowerSyncException): Unit = throw exception
19+
20+
/**
21+
* Creates a [ConnectionMethod] based on simple booleans, because creating the actual instance with
22+
* the default constructor is not possible from Swift due to an optional argument with an internal
23+
* default value.
24+
*/
25+
@OptIn(ExperimentalPowerSyncAPI::class)
26+
public fun createSyncOptions(
27+
newClient: Boolean,
28+
webSocket: Boolean,
29+
userAgent: String,
30+
): SyncOptions =
31+
SyncOptions(
32+
newClientImplementation = newClient,
33+
method =
34+
if (webSocket) {
35+
ConnectionMethod.WebSocket()
36+
} else {
37+
ConnectionMethod.Http
38+
},
39+
userAgent = userAgent,
40+
)

core/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ kotlin {
175175
implementation(libs.ktor.client.contentnegotiation)
176176
implementation(libs.ktor.serialization.json)
177177
implementation(libs.kotlinx.io)
178+
implementation(libs.rsocket.core)
179+
implementation(libs.rsocket.transport.websocket)
178180
implementation(libs.kotlinx.coroutines.core)
179181
implementation(libs.kotlinx.datetime)
180182
implementation(libs.stately.concurrency)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.powersync.sync
2+
3+
import android.os.Build
4+
5+
internal actual fun userAgent(): String = "PowerSync Kotlin SDK (Android ${Build.VERSION.SDK_INT})"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.powersync.sync
2+
3+
import com.powersync.ExperimentalPowerSyncAPI
4+
5+
/**
6+
* Small utility to run tests both with the legacy Kotlin sync implementation and the new
7+
* implementation from the core extension.
8+
*/
9+
abstract class AbstractSyncTest(
10+
private val useNewSyncImplementation: Boolean,
11+
) {
12+
@OptIn(ExperimentalPowerSyncAPI::class)
13+
val options: SyncOptions get() {
14+
return SyncOptions(useNewSyncImplementation)
15+
}
16+
}

0 commit comments

Comments
 (0)