Skip to content

Attachments package #159

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 55 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
ee59eae
wip
stevensJourney Apr 1, 2025
f3ff250
wip
stevensJourney Apr 1, 2025
dbcea9f
wip tests
stevensJourney Apr 2, 2025
7de65fd
include as package in core module
stevensJourney Apr 2, 2025
adbacfb
wip: readme
stevensJourney Apr 3, 2025
d18e4d0
README updates
stevensJourney Apr 3, 2025
9a9955d
improve storage adapters
stevensJourney Apr 3, 2025
6172c08
cleanup
stevensJourney Apr 3, 2025
eb268b7
Merge remote-tracking branch 'origin/main' into attachments-package
stevensJourney Apr 3, 2025
408db0b
fix tests
stevensJourney Apr 3, 2025
6fafc3e
cleanup tests
stevensJourney Apr 3, 2025
6530ed0
cleanup deletes
stevensJourney Apr 3, 2025
561c02a
wip: Android Attachments Demo
stevensJourney Apr 4, 2025
f414eb2
Switch to open class.
stevensJourney Apr 4, 2025
67eee58
fix demo navigation state
stevensJourney Apr 6, 2025
d00f0b1
improve locking to avoid rare race conditions
stevensJourney Apr 7, 2025
c9b5077
optional attachments in demo
stevensJourney Apr 7, 2025
09eb616
cleanup service
stevensJourney Apr 7, 2025
439bb74
Merge remote-tracking branch 'origin/main' into attachments-package
stevensJourney Apr 7, 2025
8d8196c
upate tests
stevensJourney Apr 7, 2025
4efc67d
fix tests
stevensJourney Apr 7, 2025
fe0e67e
cleanup
stevensJourney Apr 8, 2025
79361c6
Merge remote-tracking branch 'origin/main' into attachments-package
stevensJourney Apr 8, 2025
8d19eed
update changelog
stevensJourney Apr 8, 2025
f1c698a
cleanup
stevensJourney Apr 8, 2025
2da25d6
Restructure the attachments Readme with some simplified wording
benitav Apr 16, 2025
2255da2
check if file exists before delete
stevensJourney Apr 16, 2025
48b3441
Move Supabase Remote Storage to Connectors module
stevensJourney Apr 16, 2025
6dfedd5
Use enum throughout for AttachmentState
stevensJourney Apr 16, 2025
75f5b28
Sync Kotlin Gradle Plugin version
stevensJourney Apr 16, 2025
5dba44a
throw IllegalStateException when deleting a missing attachment file
stevensJourney Apr 16, 2025
f729d42
use fileSystem SystemFileSystem on IOLocalStorageAdapter
stevensJourney Apr 16, 2025
66d1f9e
use Duration for Flow throttle extension
stevensJourney Apr 16, 2025
35bbd4f
Fix periodic syncing loop
stevensJourney Apr 16, 2025
e8fcf60
revert test db path
stevensJourney Apr 16, 2025
c48a288
rename SUPABASE_STORAGE_BUCKET
stevensJourney Apr 16, 2025
31d7e5c
fix build
stevensJourney Apr 16, 2025
ff39c87
Merge remote-tracking branch 'origin/main' into attachments-package
stevensJourney Apr 16, 2025
89ea92c
update shared build plugin
stevensJourney Apr 16, 2025
b0723b1
wip: improve coroutine scope concurrency
stevensJourney Apr 16, 2025
72c8288
accept input scope
stevensJourney Apr 17, 2025
93e3381
lint fixes
stevensJourney Apr 17, 2025
6cdbb09
fix ios test build
stevensJourney Apr 17, 2025
032e8b6
Readme polish
benitav Apr 17, 2025
ec011a5
Cleanup KDoc comments. Sync with Swift implementation.
stevensJourney Apr 17, 2025
7c5152d
add changelog entry
stevensJourney Apr 17, 2025
b4d4326
cleanup
stevensJourney Apr 17, 2025
f4e9b78
test
stevensJourney Apr 17, 2025
5fd3f84
test
stevensJourney Apr 17, 2025
39ea649
test
stevensJourney Apr 17, 2025
d1760c5
test
stevensJourney Apr 17, 2025
5b2f590
cleanup changelog
stevensJourney Apr 17, 2025
4208b9e
cleanup coroutine scopes
stevensJourney Apr 22, 2025
e06be2b
Update comments on open classes
stevensJourney Apr 22, 2025
7cf5638
Improve boolean hasSynced. Make tests more stable.
stevensJourney Apr 22, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Sqlite operation failure database is locked attempted to run migration and failed. closing connection
```
* Fix race condition causing data received during uploads not to be applied.
* Added Attachment helpers

## 1.0.0-BETA28

Expand Down
1 change: 1 addition & 0 deletions connectors/supabase/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ kotlin {
implementation(libs.kotlinx.coroutines.core)
implementation(libs.supabase.client)
api(libs.supabase.auth)
api(libs.supabase.storage)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import io.github.jan.supabase.auth.user.UserSession
import io.github.jan.supabase.createSupabaseClient
import io.github.jan.supabase.postgrest.Postgrest
import io.github.jan.supabase.postgrest.from
import io.github.jan.supabase.storage.BucketApi
import io.github.jan.supabase.storage.Storage
import io.github.jan.supabase.storage.storage
import io.ktor.client.plugins.HttpSend
import io.ktor.client.plugins.plugin
import io.ktor.client.statement.bodyAsText
Expand All @@ -31,6 +34,7 @@ import kotlinx.serialization.json.Json
public class SupabaseConnector(
public val supabaseClient: SupabaseClient,
public val powerSyncEndpoint: String,
private val storageBucket: String? = null,
) : PowerSyncBackendConnector() {
private var errorCode: String? = null

Expand All @@ -52,17 +56,29 @@ public class SupabaseConnector(
}
}

public fun storageBucket(): BucketApi {
if (storageBucket == null) {
throw Exception("No bucket has been specified")
}
return supabaseClient.storage[storageBucket]
}

public constructor(
supabaseUrl: String,
supabaseKey: String,
powerSyncEndpoint: String,
storageBucket: String? = null,
) : this(
supabaseClient =
createSupabaseClient(supabaseUrl, supabaseKey) {
install(Auth)
install(Postgrest)
if (storageBucket != null) {
install(Storage)
}
},
powerSyncEndpoint = powerSyncEndpoint,
storageBucket = storageBucket,
)

init {
Expand All @@ -81,7 +97,10 @@ public class SupabaseConnector(
val responseText = response.bodyAsText()

try {
val error = Json { coerceInputValues = true }.decodeFromString<Map<String, String?>>(responseText)
val error =
Json { coerceInputValues = true }.decodeFromString<Map<String, String?>>(
responseText,
)
errorCode = error["code"]
} catch (e: Exception) {
Logger.e("Failed to parse error response: $e")
Expand Down Expand Up @@ -139,7 +158,9 @@ public class SupabaseConnector(
check(supabaseClient.auth.sessionStatus.value is SessionStatus.Authenticated) { "Supabase client is not authenticated" }

// Use Supabase token for PowerSync
val session = supabaseClient.auth.currentSessionOrNull() ?: error("Could not fetch Supabase credentials")
val session =
supabaseClient.auth.currentSessionOrNull()
?: error("Could not fetch Supabase credentials")

check(session.user != null) { "No user data" }

Expand Down
8 changes: 7 additions & 1 deletion core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ structure:
## Note on SQLDelight

The PowerSync core module, internally makes use
of [SQLDelight](https://sqldelight.github.io/sqldelight/latest/) for it database API and typesafe database
of [SQLDelight](https://sqldelight.github.io/sqldelight/latest/) for it database API and typesafe
database
query generation.

The PowerSync core module does not currently support integrating with SQLDelight from client
applications.

## Attachment Helpers

This module contains attachment helpers under the `com.powersync.attachments` package. See
the [Attachment Helpers README](./src/commonMain/kotlin/com/powersync/attachments/README.md)
44 changes: 3 additions & 41 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import org.gradle.internal.os.OperatingSystem
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
import org.jetbrains.kotlin.konan.target.Family


plugins {
Expand All @@ -19,6 +17,7 @@ plugins {
alias(libs.plugins.downloadPlugin)
alias(libs.plugins.kotlinter)
id("com.powersync.plugins.sonatype")
id("com.powersync.plugins.sharedbuild")
alias(libs.plugins.mokkery)
alias(libs.plugins.kotlin.atomicfu)
}
Expand Down Expand Up @@ -72,29 +71,6 @@ val downloadPowersyncDesktopBinaries by tasks.registering(Download::class) {
onlyIfModified(true)
}

val downloadPowersyncFramework by tasks.registering(Download::class) {
val coreVersion =
libs.versions.powersync.core
.get()
val framework =
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/powersync-sqlite-core.xcframework.zip"

src(framework)
dest(binariesFolder.map { it.file("framework/powersync-sqlite-core.xcframework.zip") })
onlyIfModified(true)
}

val unzipPowersyncFramework by tasks.registering(Copy::class) {
dependsOn(downloadPowersyncFramework)

from(
zipTree(downloadPowersyncFramework.get().dest).matching {
include("powersync-sqlite-core.xcframework/**")
},
)
into(binariesFolder.map { it.dir("framework") })
}

val sqliteJDBCFolder =
project.layout.buildDirectory
.dir("jdbc")
Expand Down Expand Up @@ -178,20 +154,6 @@ kotlin {
}
}

if (konanTarget.family == Family.IOS && konanTarget.name.contains("simulator")) {
binaries.withType<TestExecutable>().configureEach {
linkTaskProvider.configure { dependsOn(unzipPowersyncFramework) }
linkerOpts("-framework", "powersync-sqlite-core")
val frameworkRoot =
binariesFolder
.map { it.dir("framework/powersync-sqlite-core.xcframework/ios-arm64_x86_64-simulator") }
.get()
.asFile.path

linkerOpts("-F", frameworkRoot)
linkerOpts("-rpath", frameworkRoot)
}
}
/*
If we ever need macOS support:
{
Expand Down Expand Up @@ -316,8 +278,8 @@ android {
}

androidComponents.onVariants {
tasks.named("preBuild") {
dependsOn(moveJDBCJNIFiles)
tasks.named("preBuild") {
dependsOn(moveJDBCJNIFiles)
}
}

Expand Down
Loading