@@ -4,15 +4,23 @@ package com.powersync
44
55import androidx.sqlite.SQLiteConnection
66import androidx.sqlite.execSQL
7+ import com.powersync.bucket.StreamPriority
78import com.powersync.db.NativeConnectionFactory
89import com.powersync.db.crud.CrudTransaction
910import com.powersync.sync.SyncClientConfiguration
1011import com.powersync.sync.SyncOptions
12+ import com.powersync.sync.SyncStatusData
13+ import com.powersync.sync.SyncStream
14+ import com.powersync.sync.SyncStreamDescription
15+ import com.powersync.sync.SyncStreamStatus
16+ import com.powersync.sync.SyncStreamSubscription
1117import io.ktor.client.plugins.logging.LogLevel
1218import io.ktor.client.plugins.logging.Logging
19+ import kotlinx.coroutines.CancellationException
1320import kotlinx.coroutines.flow.Flow
1421import kotlinx.coroutines.flow.catch
1522import kotlinx.coroutines.flow.map
23+ import kotlin.time.Duration.Companion.seconds
1624import io.ktor.client.plugins.logging.Logger as KtorLogger
1725
1826public fun sqlite3DatabaseFactory (initialStatements : List <String >): PersistentConnectionFactory {
@@ -132,3 +140,26 @@ public fun errorHandledCrudTransactions(db: PowerSyncDatabase): Flow<PowerSyncRe
132140 throw it
133141 }
134142 }
143+
144+ /* *
145+ * Calls [SyncStream.subscribe] with types that are more convenient to construct in Swift:
146+ *
147+ * The `ttl` uses a [Double] representing seconds, `priority` is represented as the priority number
148+ * instead of the [StreamPriority].
149+ */
150+ @Throws(PowerSyncException ::class , CancellationException ::class )
151+ public suspend fun syncStreamSubscribeSwift (stream : SyncStream , ttl : Double? , priority : Int? ): SyncStreamSubscription {
152+ return stream.subscribe(
153+ ttl = ttl?.seconds,
154+ priority = priority?.let { StreamPriority (it) },
155+ )
156+ }
157+
158+ public fun syncStatusForStream (status : SyncStatusData , name : String , parameters : Map <String , Any ?>? ): SyncStreamStatus ? {
159+ return status.forStream(object : SyncStreamDescription {
160+ override val name: String
161+ get() = name
162+ override val parameters: Map <String , Any ?>?
163+ get() = parameters
164+ })
165+ }
0 commit comments