Skip to content

Add sync implementation from core extension #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7644f00
Add instruction class for core extension
simolus3 Apr 24, 2025
3afb537
Fix sync integration tests
simolus3 Apr 29, 2025
a472d50
Start with rsocket support
simolus3 Apr 29, 2025
e428df3
Add RSocket client
simolus3 May 6, 2025
6e127f1
Better logs for unknown requests
simolus3 May 6, 2025
15a7674
Test token expiry handling
simolus3 May 6, 2025
90b79b1
Dump sync stream to file
simolus3 May 7, 2025
5b513e5
Remove unused imports
simolus3 May 7, 2025
c8b01ee
Merge remote-tracking branch 'origin/main' into rust-sync-client
simolus3 May 7, 2025
803c1ed
Restore support for old implementation
simolus3 May 8, 2025
9b3fd05
Make public
simolus3 May 8, 2025
90714b5
Reformat
simolus3 May 8, 2025
e002c26
Merge remote-tracking branch 'origin/main' into rust-sync-client
simolus3 May 21, 2025
8830a8f
Merge remote-tracking branch 'origin/main' into rust-sync-client
simolus3 Jun 12, 2025
2c2332f
Fix sync progress regression
simolus3 Jun 12, 2025
3caf26d
Fix passing parameters
simolus3 Jun 12, 2025
ee121e7
Disable configuration cache
simolus3 Jun 12, 2025
eeade05
Revert extension loading tmp changes
simolus3 Jun 12, 2025
6618b23
Revert changes to demo for now
simolus3 Jun 12, 2025
1b03b8a
Merge branch 'main' into rust-sync-client
simolus3 Jun 19, 2025
834955a
Don't leak RSocket into API
simolus3 Jun 19, 2025
07e8616
Add changelog entry
simolus3 Jun 19, 2025
b67a485
Warn for unknown instructions instead of throwing
simolus3 Jun 19, 2025
217d03a
Add helper for Swift SDK
simolus3 Jun 19, 2025
0eed4e4
Make user agent configurable
simolus3 Jun 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
# Changelog

## 1.1.2 (pending)

## 1.2.0 (pending)

* Add a new sync client implementation written in Rust instead of Kotlin. While this client is still
experimental, we intend to make it the default in the future. The main benefit of this client is
faster sync performance, but upcoming features will also require this client. We encourage
interested users to try it out by opting in to `ExperimentalPowerSyncAPI` and passing options when
connecting:
```Kotlin
//@file:OptIn(ExperimentalPowerSyncAPI::class)
database.connect(MyConnector(), options = SyncOptions(
newClientImplementation = true,
))
```
Switching between the clients can be done at any time without compatibility issues. If you run
into issues with the new client, please reach out to us!
* In addition to HTTP streams, the Kotlin SDK also supports fetching sync instructions from the
PowerSync service in a binary format. This requires the new sync client, and can then be enabled
on the sync options:
```Kotlin
//@file:OptIn(ExperimentalPowerSyncAPI::class)
database.connect(MyConnector(), options = SyncOptions(
newClientImplementation = true,
method = ConnectionMethod.WebSocket()
))
```
* [Android, JVM] Use version `0.4.0` of `powersync-sqlite-core`.

## 1.1.1
Expand Down
25 changes: 25 additions & 0 deletions PowerSyncKotlin/src/appleMain/kotlin/com/powersync/SDK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

package com.powersync

import com.powersync.sync.ConnectionMethod
import com.powersync.sync.SyncOptions

/**
* Helper class designed to bridge SKIEE methods and allow them to throw
* `PowerSyncException`. This is necessary because these exceptions cannot
Expand All @@ -13,3 +16,25 @@ package com.powersync
*/
@Throws(PowerSyncException::class)
public fun throwPowerSyncException(exception: PowerSyncException): Unit = throw exception

/**
* Creates a [ConnectionMethod] based on simple booleans, because creating the actual instance with
* the default constructor is not possible from Swift due to an optional argument with an internal
* default value.
*/
@OptIn(ExperimentalPowerSyncAPI::class)
public fun createSyncOptions(
newClient: Boolean,
webSocket: Boolean,
userAgent: String,
): SyncOptions =
SyncOptions(
newClientImplementation = newClient,
method =
if (webSocket) {
ConnectionMethod.WebSocket()
} else {
ConnectionMethod.Http
},
userAgent = userAgent,
)
2 changes: 2 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ kotlin {
implementation(libs.ktor.client.contentnegotiation)
implementation(libs.ktor.serialization.json)
implementation(libs.kotlinx.io)
implementation(libs.rsocket.core)
implementation(libs.rsocket.transport.websocket)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.datetime)
implementation(libs.stately.concurrency)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.powersync.sync

import android.os.Build

internal actual fun userAgent(): String = "PowerSync Kotlin SDK (Android ${Build.VERSION.SDK_INT})"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.powersync.sync

import com.powersync.ExperimentalPowerSyncAPI

/**
* Small utility to run tests both with the legacy Kotlin sync implementation and the new
* implementation from the core extension.
*/
abstract class AbstractSyncTest(
private val useNewSyncImplementation: Boolean,
) {
@OptIn(ExperimentalPowerSyncAPI::class)
val options: SyncOptions get() {
return SyncOptions(useNewSyncImplementation)
}
}
Loading