Skip to content

Commit 90714b5

Browse files
committed
Reformat
1 parent 9b3fd05 commit 90714b5

File tree

20 files changed

+285
-190
lines changed

20 files changed

+285
-190
lines changed

core/src/commonIntegrationTest/kotlin/com/powersync/sync/AbstractSyncTest.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ package com.powersync.sync
22

33
import com.powersync.ExperimentalPowerSyncAPI
44

5-
abstract class AbstractSyncTest(private val useNewSyncImplementation: Boolean) {
6-
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+
) {
712
@OptIn(ExperimentalPowerSyncAPI::class)
813
val options: SyncOptions get() {
914
return SyncOptions(useNewSyncImplementation)
1015
}
1116
}
12-

core/src/commonIntegrationTest/kotlin/com/powersync/sync/SyncIntegrationTest.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ import kotlin.test.assertNotNull
3535
import kotlin.time.Duration.Companion.seconds
3636

3737
@OptIn(LegacySyncImplementation::class)
38-
abstract class BaseSyncIntegrationTest(useNewSyncImplementation: Boolean) : AbstractSyncTest(
39-
useNewSyncImplementation
40-
) {
38+
abstract class BaseSyncIntegrationTest(
39+
useNewSyncImplementation: Boolean,
40+
) : AbstractSyncTest(
41+
useNewSyncImplementation,
42+
) {
4143
private suspend fun PowerSyncDatabase.expectUserCount(amount: Int) {
4244
val users = getAll("SELECT * FROM users;") { UserRow.from(it) }
4345
users shouldHaveSize amount
@@ -560,9 +562,9 @@ abstract class BaseSyncIntegrationTest(useNewSyncImplementation: Boolean) : Abst
560562
}
561563
}
562564

563-
class LegacySyncIntegrationTest: BaseSyncIntegrationTest(false)
565+
class LegacySyncIntegrationTest : BaseSyncIntegrationTest(false)
564566

565-
class NewSyncIntegrationTest: BaseSyncIntegrationTest(true) {
567+
class NewSyncIntegrationTest : BaseSyncIntegrationTest(true) {
566568
// The legacy sync implementation doesn't prefetch credentials.
567569

568570
@OptIn(LegacySyncImplementation::class)
@@ -571,10 +573,11 @@ class NewSyncIntegrationTest: BaseSyncIntegrationTest(true) {
571573
databaseTest {
572574
val prefetchCalled = CompletableDeferred<Unit>()
573575
val completePrefetch = CompletableDeferred<Unit>()
574-
every { connector.prefetchCredentials() } returns scope.launch {
575-
prefetchCalled.complete(Unit)
576-
completePrefetch.await()
577-
}
576+
every { connector.prefetchCredentials() } returns
577+
scope.launch {
578+
prefetchCalled.complete(Unit)
579+
completePrefetch.await()
580+
}
578581

579582
turbineScope(timeout = 10.0.seconds) {
580583
val turbine = database.currentStatus.asFlow().testIn(this)

core/src/commonIntegrationTest/kotlin/com/powersync/sync/SyncProgressTest.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import kotlin.test.assertNull
1919
import kotlin.test.assertTrue
2020

2121
@OptIn(LegacySyncImplementation::class)
22-
abstract class BaseSyncProgressTest(useNewSyncImplementation: Boolean) : AbstractSyncTest(
23-
useNewSyncImplementation
24-
) {
22+
abstract class BaseSyncProgressTest(
23+
useNewSyncImplementation: Boolean,
24+
) : AbstractSyncTest(
25+
useNewSyncImplementation,
26+
) {
2527
private var lastOpId = 0
2628

2729
@BeforeTest
@@ -345,5 +347,6 @@ abstract class BaseSyncProgressTest(useNewSyncImplementation: Boolean) : Abstrac
345347
}
346348
}
347349

348-
class LegacySyncProgressTest: BaseSyncProgressTest(false)
349-
class NewSyncProgressTest: BaseSyncProgressTest(true)
350+
class LegacySyncProgressTest : BaseSyncProgressTest(false)
351+
352+
class NewSyncProgressTest : BaseSyncProgressTest(true)

core/src/commonIntegrationTest/kotlin/com/powersync/testutils/TestUtils.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import co.touchlab.kermit.Severity
99
import co.touchlab.kermit.TestConfig
1010
import co.touchlab.kermit.TestLogWriter
1111
import com.powersync.DatabaseDriverFactory
12-
import com.powersync.ExperimentalPowerSyncAPI
1312
import com.powersync.bucket.WriteCheckpointData
1413
import com.powersync.bucket.WriteCheckpointResponse
1514
import com.powersync.connectors.PowerSyncBackendConnector
@@ -19,7 +18,6 @@ import com.powersync.db.PowerSyncDatabaseImpl
1918
import com.powersync.db.schema.Schema
2019
import com.powersync.sync.LegacySyncImplementation
2120
import com.powersync.sync.SyncLine
22-
import com.powersync.sync.SyncOptions
2321
import dev.mokkery.answering.returns
2422
import dev.mokkery.everySuspend
2523
import dev.mokkery.mock

core/src/commonMain/kotlin/com/powersync/ExperimentalPowerSyncAPI.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@ package com.powersync
22

33
@RequiresOptIn(message = "This API is experimental and not covered by PowerSync semver releases. It can be changed at any time")
44
@Retention(AnnotationRetention.BINARY)
5-
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR)
5+
@Target(
6+
AnnotationTarget.CLASS,
7+
AnnotationTarget.FUNCTION,
8+
AnnotationTarget.CONSTRUCTOR,
9+
AnnotationTarget.PROPERTY,
10+
AnnotationTarget.VALUE_PARAMETER,
11+
)
612
public annotation class ExperimentalPowerSyncAPI

core/src/commonMain/kotlin/com/powersync/PowerSyncDatabase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public interface PowerSyncDatabase : Queries {
9595
crudThrottleMs: Long = 1000L,
9696
retryDelayMs: Long = 5000L,
9797
params: Map<String, JsonParam?> = emptyMap(),
98-
options: SyncOptions = SyncOptions.defaults
98+
options: SyncOptions = SyncOptions.defaults,
9999
)
100100

101101
/**

core/src/commonMain/kotlin/com/powersync/bucket/BucketStorage.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,32 @@ internal interface BucketStorage {
3131

3232
@LegacySyncImplementation
3333
suspend fun getBucketStates(): List<BucketState>
34+
3435
@LegacySyncImplementation
3536
suspend fun getBucketOperationProgress(): Map<String, LocalOperationCounters>
37+
3638
@LegacySyncImplementation
3739
suspend fun removeBuckets(bucketsToDelete: List<String>)
40+
3841
@LegacySyncImplementation
3942
fun setTargetCheckpoint(checkpoint: Checkpoint)
43+
4044
@LegacySyncImplementation
4145
suspend fun saveSyncData(syncDataBatch: SyncDataBatch)
46+
4247
@LegacySyncImplementation
4348
suspend fun syncLocalDatabase(
4449
targetCheckpoint: Checkpoint,
4550
partialPriority: BucketPriority? = null,
4651
): SyncLocalDatabaseResult
4752

48-
suspend fun control(op: String, payload: String?): List<Instruction>
49-
suspend fun control(op: String, payload: ByteArray): List<Instruction>
53+
suspend fun control(
54+
op: String,
55+
payload: String?,
56+
): List<Instruction>
57+
58+
suspend fun control(
59+
op: String,
60+
payload: ByteArray,
61+
): List<Instruction>
5062
}

core/src/commonMain/kotlin/com/powersync/bucket/BucketStorageImpl.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ internal class BucketStorageImpl(
153153
val rows =
154154
db.getAll("SELECT name, count_at_last, count_since_last FROM ps_buckets") { cursor ->
155155
cursor.getString(0)!! to
156-
LocalOperationCounters(
157-
atLast = cursor.getLong(1)!!.toInt(),
158-
sinceLast = cursor.getLong(2)!!.toInt(),
159-
)
156+
LocalOperationCounters(
157+
atLast = cursor.getLong(1)!!.toInt(),
158+
sinceLast = cursor.getLong(2)!!.toInt(),
159+
)
160160
}
161161

162162
for ((name, counters) in rows) {
@@ -365,18 +365,22 @@ internal class BucketStorageImpl(
365365
return JsonUtil.json.decodeFromString<List<Instruction>>(result)
366366
}
367367

368-
override suspend fun control(op: String, payload: String?): List<Instruction> {
369-
return db.writeTransaction { tx ->
368+
override suspend fun control(
369+
op: String,
370+
payload: String?,
371+
): List<Instruction> =
372+
db.writeTransaction { tx ->
370373
logger.v { "powersync_control($op, $payload)" }
371374

372375
tx.get("SELECT powersync_control(?, ?) AS r", listOf(op, payload), ::handleControlResult)
373376
}
374-
}
375377

376-
override suspend fun control(op: String, payload: ByteArray): List<Instruction> {
377-
return db.writeTransaction { tx ->
378+
override suspend fun control(
379+
op: String,
380+
payload: ByteArray,
381+
): List<Instruction> =
382+
db.writeTransaction { tx ->
378383
logger.v { "powersync_control($op, binary payload)" }
379384
tx.get("SELECT powersync_control(?, ?) AS r", listOf(op, payload), ::handleControlResult)
380385
}
381-
}
382386
}

core/src/commonMain/kotlin/com/powersync/connectors/PowerSyncBackendConnector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public abstract class PowerSyncBackendConnector {
5959
public open fun prefetchCredentials(): Job {
6060
fetchRequest?.takeIf { it.isActive }?.let { return it }
6161

62-
val request =
62+
val request =
6363
scope.launch {
6464
fetchCredentials().also { value ->
6565
cachedCredentials = value

core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.powersync.db
22

33
import co.touchlab.kermit.Logger
44
import com.powersync.DatabaseDriverFactory
5-
import com.powersync.ExperimentalPowerSyncAPI
65
import com.powersync.PowerSyncDatabase
76
import com.powersync.PowerSyncException
87
import com.powersync.bucket.BucketPriority
@@ -153,7 +152,7 @@ internal class PowerSyncDatabaseImpl(
153152
crudThrottleMs: Long,
154153
retryDelayMs: Long,
155154
params: Map<String, JsonParam?>,
156-
options: SyncOptions
155+
options: SyncOptions,
157156
) {
158157
waitReady()
159158
mutex.withLock {

0 commit comments

Comments
 (0)