Skip to content

Commit b27f52a

Browse files
committed
Reformat
1 parent bc6cc85 commit b27f52a

File tree

8 files changed

+134
-111
lines changed

8 files changed

+134
-111
lines changed

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

Lines changed: 91 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -695,85 +695,104 @@ class NewSyncIntegrationTest : BaseSyncIntegrationTest(true) {
695695

696696
@Test
697697
@OptIn(ExperimentalPowerSyncAPI::class, LegacySyncImplementation::class)
698-
fun rawTables() = databaseTest(createInitialDatabase = false) {
699-
val db = openDatabase(Schema(listOf(
700-
RawTable(
701-
name = "lists",
702-
put = PendingStatement(
703-
"INSERT OR REPLACE INTO lists (id, name) VALUES (?, ?)",
704-
listOf(PendingStatementParameter.Id, PendingStatementParameter.Column("name"))
705-
),
706-
delete = PendingStatement(
707-
"DELETE FROM lists WHERE id = ?", listOf(PendingStatementParameter.Id)
708-
)
709-
)
710-
)))
711-
712-
db.execute("CREATE TABLE lists (id TEXT NOT NULL PRIMARY KEY, name TEXT)")
713-
turbineScope(timeout = 10.0.seconds) {
714-
val query = db.watch("SELECT * FROM lists", throttleMs = 0L) {
715-
it.getString(0) to it.getString(1)
716-
}.testIn(this)
717-
query.awaitItem() shouldBe emptyList()
718-
719-
db.connect(connector, options = options)
720-
syncLines.send(SyncLine.FullCheckpoint(Checkpoint(
721-
lastOpId = "1",
722-
checksums = listOf(BucketChecksum("a", checksum = 0)),
723-
)))
724-
syncLines.send(
725-
SyncLine.SyncDataBucket(
726-
bucket = "a",
727-
data =
698+
fun rawTables() =
699+
databaseTest(createInitialDatabase = false) {
700+
val db =
701+
openDatabase(
702+
Schema(
728703
listOf(
729-
OplogEntry(
730-
checksum = 0L,
731-
data =
732-
JsonUtil.json.encodeToString(
733-
mapOf(
734-
"name" to "custom list",
735-
),
704+
RawTable(
705+
name = "lists",
706+
put =
707+
PendingStatement(
708+
"INSERT OR REPLACE INTO lists (id, name) VALUES (?, ?)",
709+
listOf(PendingStatementParameter.Id, PendingStatementParameter.Column("name")),
710+
),
711+
delete =
712+
PendingStatement(
713+
"DELETE FROM lists WHERE id = ?",
714+
listOf(PendingStatementParameter.Id),
736715
),
737-
op = OpType.PUT,
738-
opId = "1",
739-
rowId = "my_list",
740-
rowType = "lists",
741716
),
742717
),
743-
after = null,
744-
nextAfter = null,
745-
),
746-
)
747-
syncLines.send(SyncLine.CheckpointComplete("1"))
748-
749-
query.awaitItem() shouldBe listOf("my_list" to "custom list")
718+
),
719+
)
750720

751-
syncLines.send(SyncLine.FullCheckpoint(Checkpoint(
752-
lastOpId = "2",
753-
checksums = listOf(BucketChecksum("a", checksum = 0)),
754-
)))
755-
syncLines.send(
756-
SyncLine.SyncDataBucket(
757-
bucket = "a",
758-
data =
759-
listOf(
760-
OplogEntry(
761-
checksum = 0L,
762-
data = null,
763-
op = OpType.REMOVE,
764-
opId = "2",
765-
rowId = "my_list",
766-
rowType = "lists",
721+
db.execute("CREATE TABLE lists (id TEXT NOT NULL PRIMARY KEY, name TEXT)")
722+
turbineScope(timeout = 10.0.seconds) {
723+
val query =
724+
db
725+
.watch("SELECT * FROM lists", throttleMs = 0L) {
726+
it.getString(0) to it.getString(1)
727+
}.testIn(this)
728+
query.awaitItem() shouldBe emptyList()
729+
730+
db.connect(connector, options = options)
731+
syncLines.send(
732+
SyncLine.FullCheckpoint(
733+
Checkpoint(
734+
lastOpId = "1",
735+
checksums = listOf(BucketChecksum("a", checksum = 0)),
736+
),
737+
),
738+
)
739+
syncLines.send(
740+
SyncLine.SyncDataBucket(
741+
bucket = "a",
742+
data =
743+
listOf(
744+
OplogEntry(
745+
checksum = 0L,
746+
data =
747+
JsonUtil.json.encodeToString(
748+
mapOf(
749+
"name" to "custom list",
750+
),
751+
),
752+
op = OpType.PUT,
753+
opId = "1",
754+
rowId = "my_list",
755+
rowType = "lists",
756+
),
767757
),
758+
after = null,
759+
nextAfter = null,
760+
),
761+
)
762+
syncLines.send(SyncLine.CheckpointComplete("1"))
763+
764+
query.awaitItem() shouldBe listOf("my_list" to "custom list")
765+
766+
syncLines.send(
767+
SyncLine.FullCheckpoint(
768+
Checkpoint(
769+
lastOpId = "2",
770+
checksums = listOf(BucketChecksum("a", checksum = 0)),
768771
),
769-
after = null,
770-
nextAfter = null,
771-
),
772-
)
773-
syncLines.send(SyncLine.CheckpointComplete("1"))
772+
),
773+
)
774+
syncLines.send(
775+
SyncLine.SyncDataBucket(
776+
bucket = "a",
777+
data =
778+
listOf(
779+
OplogEntry(
780+
checksum = 0L,
781+
data = null,
782+
op = OpType.REMOVE,
783+
opId = "2",
784+
rowId = "my_list",
785+
rowType = "lists",
786+
),
787+
),
788+
after = null,
789+
nextAfter = null,
790+
),
791+
)
792+
syncLines.send(SyncLine.CheckpointComplete("1"))
774793

775-
query.awaitItem() shouldBe emptyList()
776-
query.cancelAndIgnoreRemainingEvents()
794+
query.awaitItem() shouldBe emptyList()
795+
query.cancelAndIgnoreRemainingEvents()
796+
}
777797
}
778-
}
779798
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ internal sealed interface PowerSyncControlArguments {
6060
@Serializable
6161
class Start(
6262
val parameters: JsonObject,
63-
val schema: SerializableSchema
63+
val schema: SerializableSchema,
6464
) : PowerSyncControlArguments
6565

6666
data object Stop : PowerSyncControlArguments

core/src/commonMain/kotlin/com/powersync/db/internal/InternalDatabaseImpl.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.powersync.utils.JsonUtil
1212
import com.powersync.utils.throttle
1313
import kotlinx.coroutines.CoroutineScope
1414
import kotlinx.coroutines.Dispatchers
15-
import kotlinx.coroutines.FlowPreview
1615
import kotlinx.coroutines.IO
1716
import kotlinx.coroutines.flow.Flow
1817
import kotlinx.coroutines.flow.SharedFlow

core/src/commonMain/kotlin/com/powersync/db/schema/RawTable.kt

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package com.powersync.db.schema
22

33
import com.powersync.ExperimentalPowerSyncAPI
44
import com.powersync.sync.SyncOptions
5-
import kotlinx.serialization.Serializable
65
import kotlinx.serialization.json.JsonElement
7-
import kotlinx.serialization.json.JsonObjectBuilder
86
import kotlinx.serialization.json.JsonPrimitive
97
import kotlinx.serialization.json.buildJsonArray
108
import kotlinx.serialization.json.buildJsonObject
@@ -31,40 +29,44 @@ public class RawTable(
3129
* The statement to run when the sync client wants to delete a row.
3230
*/
3331
public val delete: PendingStatement,
34-
): BaseTable {
32+
) : BaseTable {
3533
override fun validate() {
3634
// We don't currently have any validation for raw tables
3735
}
3836

39-
internal fun serialize(): JsonElement {
40-
return buildJsonObject {
37+
internal fun serialize(): JsonElement =
38+
buildJsonObject {
4139
put("name", name)
4240
put("put", put.serialize())
4341
put("delete", delete.serialize())
4442
}
45-
}
4643
}
4744

4845
@ExperimentalPowerSyncAPI
4946
public class PendingStatement(
5047
public val sql: String,
5148
public val parameters: List<PendingStatementParameter>,
5249
) {
53-
internal fun serialize(): JsonElement {
54-
return buildJsonObject {
50+
internal fun serialize(): JsonElement =
51+
buildJsonObject {
5552
put("sql", sql)
56-
put("params", buildJsonArray {
57-
for (param in parameters) {
58-
add(when(param) {
59-
is PendingStatementParameter.Column -> buildJsonObject {
60-
put("Column", param.name)
61-
}
62-
PendingStatementParameter.Id -> JsonPrimitive("Id")
63-
})
64-
}
65-
})
53+
put(
54+
"params",
55+
buildJsonArray {
56+
for (param in parameters) {
57+
add(
58+
when (param) {
59+
is PendingStatementParameter.Column ->
60+
buildJsonObject {
61+
put("Column", param.name)
62+
}
63+
PendingStatementParameter.Id -> JsonPrimitive("Id")
64+
},
65+
)
66+
}
67+
},
68+
)
6669
}
67-
}
6870
}
6971

7072
/**
@@ -75,14 +77,15 @@ public sealed interface PendingStatementParameter {
7577
/**
7678
* Resolves to the id of the affected row.
7779
*/
78-
public object Id: PendingStatementParameter
80+
public object Id : PendingStatementParameter
7981

8082
/**
8183
* Resolves to the value of a column in the added row.
8284
*
8385
* This is only available for [RawTable.put] - in [RawTable.delete] statements, only the [Id]
8486
* can be used as a value.
8587
*/
86-
public class Column(public val name: String): PendingStatementParameter
88+
public class Column(
89+
public val name: String,
90+
) : PendingStatementParameter
8791
}
88-

core/src/commonMain/kotlin/com/powersync/db/schema/Schema.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ public data class Schema internal constructor(
1616
val tables: List<Table>,
1717
val rawTables: List<RawTable>,
1818
) {
19-
public constructor(tables: List<BaseTable>): this(
19+
public constructor(tables: List<BaseTable>) : this(
2020
tables.filterIsInstance<Table>(),
21-
tables.filterIsInstance<RawTable>()
21+
tables.filterIsInstance<RawTable>(),
2222
)
2323

2424
init {
2525
validate()
2626
}
2727

28-
internal val allTables: Sequence<BaseTable> get() = sequence {
29-
yieldAll(tables)
30-
yieldAll(rawTables)
31-
}
28+
internal val allTables: Sequence<BaseTable> get() =
29+
sequence {
30+
yieldAll(tables)
31+
yieldAll(rawTables)
32+
}
3233

3334
/**
3435
* Secondary constructor to create a schema with a variable number of tables.
@@ -80,6 +81,6 @@ internal fun Schema.toSerializable(): SerializableSchema =
8081
with(this) {
8182
SerializableSchema(
8283
tables = tables.map { it.toSerializable() },
83-
rawTables = rawTables.map { it.serialize() }
84+
rawTables = rawTables.map { it.serialize() },
8485
)
8586
}

core/src/commonMain/kotlin/com/powersync/db/schema/Table.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public data class Table(
5353
* CRUD entries.
5454
*/
5555
val ignoreEmptyUpdates: Boolean = false,
56-
): BaseTable {
56+
) : BaseTable {
5757
init {
5858
/**
5959
* Need to set the column definition for each index column.

core/src/commonMain/kotlin/com/powersync/sync/SyncStream.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import com.powersync.bucket.WriteCheckpointResponse
1313
import com.powersync.connectors.PowerSyncBackendConnector
1414
import com.powersync.db.crud.CrudEntry
1515
import com.powersync.db.schema.Schema
16-
import com.powersync.db.schema.SerializableSchema
1716
import com.powersync.db.schema.toSerializable
1817
import com.powersync.utils.JsonUtil
1918
import io.ktor.client.HttpClient
@@ -314,10 +313,12 @@ internal class SyncStream(
314313
}
315314

316315
suspend fun start() {
317-
invokeControl(PowerSyncControlArguments.Start(
318-
parameters = params,
319-
schema = schema.toSerializable(),
320-
))
316+
invokeControl(
317+
PowerSyncControlArguments.Start(
318+
parameters = params,
319+
schema = schema.toSerializable(),
320+
),
321+
)
321322

322323
var hadSyncLine = false
323324
for (line in controlInvocations) {

core/src/commonTest/kotlin/com/powersync/sync/SyncStreamTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class SyncStreamTest {
122122
params = JsonObject(emptyMap()),
123123
uploadScope = this,
124124
options = SyncOptions(),
125-
schema = Schema()
125+
schema = Schema(),
126126
)
127127

128128
syncStream.status.update { copy(connected = true) }
@@ -163,7 +163,7 @@ class SyncStreamTest {
163163
params = JsonObject(emptyMap()),
164164
uploadScope = this,
165165
options = SyncOptions(),
166-
schema = Schema()
166+
schema = Schema(),
167167
)
168168

169169
// Launch streaming sync in a coroutine that we'll cancel after verification

0 commit comments

Comments
 (0)