diff --git a/common/src/commonMain/kotlin/com/powersync/sync/Stream.kt b/common/src/commonMain/kotlin/com/powersync/sync/Stream.kt index c5977157..f40fd5b2 100644 --- a/common/src/commonMain/kotlin/com/powersync/sync/Stream.kt +++ b/common/src/commonMain/kotlin/com/powersync/sync/Stream.kt @@ -1,6 +1,9 @@ package com.powersync.sync +import com.powersync.PowerSyncException import com.powersync.bucket.StreamPriority +import kotlinx.coroutines.CancellationException +import kotlin.native.HiddenFromObjC import kotlin.time.Duration import kotlin.time.Instant @@ -73,11 +76,13 @@ public interface SyncSubscriptionDescription : SyncStreamDescription { * To obtain an instance of [SyncStream], call [com.powersync.PowerSyncDatabase.syncStream]. */ public interface SyncStream : SyncStreamDescription { + @HiddenFromObjC public suspend fun subscribe( ttl: Duration? = null, priority: StreamPriority? = null, ): SyncStreamSubscription + @Throws(PowerSyncException::class, CancellationException::class) public suspend fun unsubscribeAll() } @@ -89,6 +94,7 @@ public interface SyncStreamSubscription : SyncStreamDescription { * A variant of [com.powersync.PowerSyncDatabase.waitForFirstSync] that is specific to this * stream subscription. */ + @Throws(PowerSyncException::class, CancellationException::class) public suspend fun waitForFirstSync() /** @@ -98,5 +104,6 @@ public interface SyncStreamSubscription : SyncStreamDescription { * that stream starts running. When it expires without subscribing again, the stream will be * evicted. */ + @Throws(PowerSyncException::class, CancellationException::class) public suspend fun unsubscribe() } diff --git a/internal/PowerSyncKotlin/src/appleMain/kotlin/com/powersync/SDK.kt b/internal/PowerSyncKotlin/src/appleMain/kotlin/com/powersync/SDK.kt index 39382e2a..af504a24 100644 --- a/internal/PowerSyncKotlin/src/appleMain/kotlin/com/powersync/SDK.kt +++ b/internal/PowerSyncKotlin/src/appleMain/kotlin/com/powersync/SDK.kt @@ -4,15 +4,23 @@ package com.powersync import androidx.sqlite.SQLiteConnection import androidx.sqlite.execSQL +import com.powersync.bucket.StreamPriority import com.powersync.db.NativeConnectionFactory import com.powersync.db.crud.CrudTransaction import com.powersync.sync.SyncClientConfiguration import com.powersync.sync.SyncOptions +import com.powersync.sync.SyncStatusData +import com.powersync.sync.SyncStream +import com.powersync.sync.SyncStreamDescription +import com.powersync.sync.SyncStreamStatus +import com.powersync.sync.SyncStreamSubscription import io.ktor.client.plugins.logging.LogLevel import io.ktor.client.plugins.logging.Logging +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.map +import kotlin.time.Duration.Companion.seconds import io.ktor.client.plugins.logging.Logger as KtorLogger public fun sqlite3DatabaseFactory(initialStatements: List): PersistentConnectionFactory { @@ -132,3 +140,34 @@ public fun errorHandledCrudTransactions(db: PowerSyncDatabase): Flow?, +): SyncStreamStatus? = + status.forStream( + object : SyncStreamDescription { + override val name: String + get() = name + override val parameters: Map? + get() = parameters + }, + )