Skip to content
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

Add support for WASM-JS and migrate to Ktor 3.0.0 #311

Merged
merged 58 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
2f52216
Rename WASM target
jan-tennert Dec 1, 2023
4de336a
Merge branch 'master' into wasm
jan-tennert Dec 27, 2023
599385e
Add support for wasm
jan-tennert Dec 27, 2023
52a5602
Add wasmJs tests
jan-tennert Dec 27, 2023
9784297
fix build
jan-tennert Dec 27, 2023
527f89f
fix detekt
jan-tennert Dec 27, 2023
da8dcc5
Update version
jan-tennert Dec 27, 2023
a39d90e
Merge branch 'master' into wasm
jan-tennert Jan 2, 2024
955c57c
update version
jan-tennert Jan 2, 2024
e6e7638
Merge branch 'master' into wasm
jan-tennert Jan 4, 2024
5bc96d0
Update wasm code to match master changes
jan-tennert Jan 4, 2024
1feffa3
backport js fix to wasm-js
jan-tennert Jan 5, 2024
1888d28
Merge branch 'master' into wasm
jan-tennert Jan 5, 2024
98e4d92
Merge branch 'master' into wasm
jan-tennert Jan 10, 2024
280d0c8
Merge branch 'master' into wasm
jan-tennert Jan 30, 2024
cc54d0f
Merge branch 'master' into wasm
jan-tennert Feb 3, 2024
cdc5452
Merge branch 'master' into wasm
jan-tennert Feb 13, 2024
173376e
Merge branch 'development' into wasm
jan-tennert Feb 16, 2024
b2ccb84
Add Apollo GraphQL, Compose Auth, Compose Auth Ui support
jan-tennert Feb 16, 2024
f04c2a4
Merge branch 'development' into wasm
jan-tennert Mar 10, 2024
3566d42
Merge branch 'master' into wasm
jan-tennert Mar 16, 2024
68cc469
migrate to ktor 3.0.0
jan-tennert Mar 16, 2024
6bb3d06
bumnp apollo and version
jan-tennert Mar 16, 2024
a69299f
Merge branch 'master' into wasm
jan-tennert Mar 22, 2024
b19db74
Merge branch 'master' into wasm
jan-tennert Mar 23, 2024
b59b6e3
Merge branch 'refs/heads/master' into wasm
jan-tennert Apr 10, 2024
ad69d94
Merge branch 'master' into wasm
jan-tennert Apr 19, 2024
e4258ff
Update version
jan-tennert Apr 19, 2024
17517f4
Merge branch 'refs/heads/master' into wasm
jan-tennert May 10, 2024
760ebb1
Merge master
jan-tennert May 10, 2024
14bb9c0
fix some build errors
jan-tennert May 11, 2024
583f948
Merge branch 'refs/heads/master' into wasm
jan-tennert May 11, 2024
6fb0dad
remove image loader wasm support
jan-tennert May 11, 2024
3ba3558
add wasm js to compose auth ui
jan-tennert May 12, 2024
9a5e3d2
Merge branch 'refs/heads/master' into wasm
jan-tennert May 19, 2024
d0066e6
Merge branch 'refs/heads/master' into wasm
jan-tennert Jul 20, 2024
d46994b
Update versions
jan-tennert Jul 20, 2024
a43fee9
Merge branch 'refs/heads/master' into wasm
jan-tennert Jul 20, 2024
ff92214
Update version
jan-tennert Jul 20, 2024
236bc28
Migrate to new Ktor Beta
jan-tennert Jul 21, 2024
bd00b57
Merge branch 'refs/heads/master' into wasm
jan-tennert Jul 21, 2024
d541aaf
Fix storage-kt
jan-tennert Jul 21, 2024
e1da720
Fix another migration error
jan-tennert Jul 21, 2024
5380e4a
Fix sample
jan-tennert Jul 21, 2024
6a049ca
Merge branch 'master' into wasm
jan-tennert Jul 28, 2024
7c8f1a3
Merge branch 'master' into wasm
jan-tennert Jul 30, 2024
756266f
Merge branch 'master' into wasm
jan-tennert Aug 17, 2024
c9f8f86
Fix wasmJs implementation
jan-tennert Aug 17, 2024
265aac6
Merge branch 'master' into wasm
jan-tennert Aug 27, 2024
4fe2827
Fix test
jan-tennert Aug 27, 2024
175395d
Suppress compile only warning
jan-tennert Aug 28, 2024
2a08a13
Merge branch 'master' into wasm
jan-tennert Sep 9, 2024
8df452a
Merge branch 'master' into wasm
jan-tennert Sep 10, 2024
1aeeac4
Update docs
jan-tennert Sep 10, 2024
9f4d125
Fix typo
jan-tennert Sep 10, 2024
6402e65
Update setup-gradle
jan-tennert Sep 10, 2024
ca183e4
Remove test dep
jan-tennert Sep 10, 2024
5de416b
Fix invalid Ktor version badge
jan-tennert Sep 10, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3.1.0
uses: gradle/actions/setup-gradle@v4.0.1
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
cache-read-only: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3.1.0
uses: gradle/actions/setup-gradle@v4.0.1
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
cache-read-only: ${{ github.ref != 'refs/heads/master' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dokka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3.1.0
uses: gradle/actions/setup-gradle@v4.0.1
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
cache-read-only: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3.1.0
uses: gradle/actions/setup-gradle@v4.0.1
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
cache-read-only: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3.1.0
uses: gradle/actions/setup-gradle@v4.0.1
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
cache-read-only: ${{ github.ref != 'refs/heads/master' }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
command: [
'jvmTest testDebugUnitTest testReleaseUnitTest',
'jsTest',
'jsTest wasmJsTest',
'iosX64Test iosSimulatorArm64Test',
'macosArm64Test macosX64Test',
'tvosX64Test tvosSimulatorArm64Test',
Expand All @@ -31,7 +31,7 @@ jobs:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3.1.0
uses: gradle/actions/setup-gradle@v4.0.1
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
cache-read-only: ${{ github.ref != 'refs/heads/master' }}
Expand Down
20 changes: 12 additions & 8 deletions Functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@ Extends Supabase-kt with a multiplatform Functions client.

Supported targets:

| Target | **JVM** | **Android** | **JS** | **iOS** | **tvOS** | **watchOS** | **macOS** | **Windows** | **Linux** |
|--------|---------|-------------|--------|---------|----------|-------------|-----------|-------------|-----------|
| | ✅ | ✅ | ✅ | ✅ | ✅ | | ✅ | ✅ | ✅ |
| Target | **JVM** | **Android** | **JS** | **Wasm** | **Apple** | **Windows** | **Linux** |
|--------|---------|-------------|--------|----------|-----------|-------------|-----------|
| Status | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |

<details>

<summary>In-depth Kotlin targets</summary>

**iOS:** iosArm64, iosSimulatorArm64, iosX64

**JS**: Browser, NodeJS

**tvOS**: tvosArm64, tvosX64, tvosSimulatorArm64
**Wasm**: wasm-js

**Apple:**

- iOS: iosArm64, iosSimulatorArm64, iosX64

- tvOS: tvosArm64, tvosX64, tvosSimulatorArm64

**watchOS**: watchosArm64, watchosX64, watchosSimulatorArm64
- watchOS: watchosArm64, watchosX64, watchosSimulatorArm64

**MacOS**: macosX64, macosArm64
- MacOS: macosX64, macosArm64

**Windows**: mingwX64

Expand Down
24 changes: 14 additions & 10 deletions GoTrue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@ Extends Supabase-kt with a multiplatform GoTrue client.

Supported targets:

| Target | **JVM** | **Android** | **JS** | **iOS** | **tvOS** | **watchOS** | **macOS** | **Windows** | **Linux** |
| ------ | ------- | ----------- | ------ | ------- | -------- | ----------- | --------- | ----------- | --------- |
| | ✅ | ✅ | ✅ | ✅ | ☑️ | ☑️ | ✅ | ☑️ | ☑️ |
| Target | **JVM** | **Android** | **JS** | **Wasm** | **Apple** | **Windows** | **Linux** |
|--------|---------|-------------|--------|----------|-----------|-------------|-----------|
| Status | ✅ | ✅ | ✅ | | ☑️* | ☑️ | ☑️ |

> Native support is experimental and needs feedback
>
> ☑️ = No built-in OAuth support. Linux has no support for persistent session storage.

\* **iOS and macOS are fully supported**

<details>

<summary>In-depth Kotlin targets</summary>

**iOS:** iosArm64, iosSimulatorArm64, iosX64

**JS**: Browser, NodeJS

**tvOS**: tvosArm64, tvosX64, tvosSimulatorArm64
**Wasm**: wasm-js

**Apple:**

- iOS: iosArm64, iosSimulatorArm64, iosX64

- tvOS: tvosArm64, tvosX64, tvosSimulatorArm64

**watchOS**: watchosArm64, watchosX64, watchosSimulatorArm64
- watchOS: watchosArm64, watchosX64, watchosSimulatorArm64

**MacOS**: macosX64, macosArm64
- MacOS: macosX64, macosArm64

**Windows**: mingwX64

Expand Down
1 change: 1 addition & 0 deletions GoTrue/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ kotlin {
withWatchos()
withMingw()
withJs()
withWasmJs()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import io.github.jan.supabase.gotrue.user.UserSession
import io.github.jan.supabase.logging.d
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.call
import io.ktor.server.response.respondText
import io.ktor.server.routing.Routing
import io.ktor.server.routing.get
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.jan.supabase.gotrue.server

import io.github.jan.supabase.annotations.SupabaseExperimental
import io.github.jan.supabase.gotrue.Auth
import io.github.jan.supabase.gotrue.AuthImpl
import io.github.jan.supabase.gotrue.openExternalUrl
Expand All @@ -11,7 +10,6 @@ import io.ktor.http.HttpStatusCode
import io.ktor.server.application.ApplicationCall
import io.ktor.server.application.ApplicationStopPreparing
import io.ktor.server.cio.CIO
import io.ktor.server.engine.ApplicationEngineEnvironment
import io.ktor.server.engine.embeddedServer
import io.ktor.server.response.respondText
import io.ktor.server.routing.routing
Expand All @@ -23,7 +21,6 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.coroutines.resume

@OptIn(SupabaseExperimental::class)
internal suspend fun createServer(
url: suspend (redirect: String) -> String,
auth: Auth,
Expand All @@ -41,7 +38,7 @@ internal suspend fun createServer(
}
coroutineScope {
val timeoutScope = launch {
val port = server.resolvedConnectors().first().port
val port = server.engine.resolvedConnectors().first().port
Auth.logger.d {
"Started OAuth callback server on port $port. Opening url in browser..."
}
Expand All @@ -64,7 +61,7 @@ internal suspend fun createServer(
}
launch {
suspendCancellableCoroutine {
server.environment.monitor.subscribe(ApplicationStopPreparing) { _ ->
server.monitor.subscribe(ApplicationStopPreparing) { _ ->
it.resume(Unit)
timeoutScope.cancel()
}
Expand All @@ -84,14 +81,9 @@ internal suspend fun shutdown(call: ApplicationCall, message: String) {

val latch = CompletableDeferred<Nothing>()
call.application.launch {
application.monitor.raise(ApplicationStopPreparing, environment)
latch.join()

environment.monitor.raise(ApplicationStopPreparing, environment)
if (environment is ApplicationEngineEnvironment) {
environment.stop()
} else {
application.dispose()
}
application.dispose()
}

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
package io.github.jan.supabase.gotrue.providers

import kotlinx.browser.window

/**
* Configuration for external authentication providers like Google, Twitter, etc.
*/
actual class ExternalAuthConfig: ExternalAuthConfigDefaults() {

/**
* The URL to redirect to after a successful login.
*
* Defaults to `Window.location.origin`
*/
var redirectUrl: String = window.location.origin

}
actual class ExternalAuthConfig: ExternalAuthConfigDefaults()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.github.jan.supabase.gotrue

import io.github.jan.supabase.plugins.CustomSerializationConfig

/**
* The configuration for [Auth]
*/
actual class AuthConfig: CustomSerializationConfig, AuthConfigDefaults()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.jan.supabase.gotrue

import io.github.jan.supabase.annotations.SupabaseInternal
import kotlinx.browser.window

@SupabaseInternal
actual fun Auth.defaultPlatformRedirectUrl(): String? = window.location.origin
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.github.jan.supabase.gotrue

import io.github.jan.supabase.SupabaseClient
import kotlinx.browser.window

internal actual suspend fun SupabaseClient.openExternalUrl(url: String) {
window.location.href = url
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.jan.supabase.gotrue.providers

/**
* Configuration for external authentication providers like Google, Twitter, etc.
*/
actual class ExternalAuthConfig: ExternalAuthConfigDefaults()
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.github.jan.supabase.gotrue

import io.github.jan.supabase.annotations.SupabaseInternal
import io.ktor.util.PlatformUtils.IS_BROWSER
import kotlinx.browser.window
import kotlinx.coroutines.launch
import org.w3c.dom.url.URL

@SupabaseInternal
actual fun Auth.setupPlatform() {
this as AuthImpl

fun checkForHash() {
if(window.location.hash.isBlank()) return
val afterHash = window.location.hash.substring(1)

if(!afterHash.contains('=')) {
// No params after hash, no need to continue
return
}
parseFragmentAndImportSession(afterHash) {
val newURL = window.location.href.split("?")[0];
window.history.replaceState(null, window.document.title, newURL);
}
}

fun checkForPCKECode() {
val url = URL(window.location.href)
val code = url.searchParams.get("code") ?: return
authScope.launch {
val session = exchangeCodeForSession(code)
importSession(session)
}
val newURL = window.location.href.split("?")[0];
window.history.replaceState(null, window.document.title, newURL);
}

if(IS_BROWSER) {
window.onhashchange = {
checkForHash()
}
window.onload = {
checkForHash()
checkForPCKECode()
}
}
}
3 changes: 3 additions & 0 deletions GoTrue/src/wasmJsTest/kotlin/platformSettings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import io.github.jan.supabase.gotrue.AuthConfig

actual fun AuthConfig.platformSettings() = Unit
20 changes: 12 additions & 8 deletions Postgrest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@ Extends Supabase-kt with a multiplatform Postgrest client.

Supported targets:

| Target | **JVM** | **Android** | **JS** | **iOS** | **tvOS** | **watchOS** | **macOS** | **Windows** | **Linux** |
| ------ | ------- | ----------- | ------ | ------- | -------- | ----------- | --------- | ----------- | --------- |
| | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Target | **JVM** | **Android** | **JS** | **Wasm** | **Apple** | **Windows** | **Linux** |
|--------|---------|-------------|--------|----------|-----------|-------------|-----------|
| Status | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |

<details>

<summary>In-depth Kotlin targets</summary>

**iOS:** iosArm64, iosSimulatorArm64, iosX64

**JS**: Browser, NodeJS

**tvOS**: tvosArm64, tvosX64, tvosSimulatorArm64
**Wasm**: wasm-js

**Apple:**

- iOS: iosArm64, iosSimulatorArm64, iosX64

- tvOS: tvosArm64, tvosX64, tvosSimulatorArm64

**watchOS**: watchosArm64, watchosX64, watchosSimulatorArm64
- watchOS: watchosArm64, watchosX64, watchosSimulatorArm64

**MacOS**: macosX64, macosArm64
- MacOS: macosX64, macosArm64

**Windows**: mingwX64

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.jan.supabase.postgrest

import io.github.jan.supabase.annotations.SupabaseInternal
import kotlin.reflect.KProperty1

@SupabaseInternal
actual fun <T, V> getSerialName(property: KProperty1<T, V>) = property.name
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ For information about supported Kotlin targets, see the corresponding module REA

[Migrating from version 1.4.X to 2.0.0](/MIGRATION.md)

*Note: [WASM](https://github.com/supabase-community/supabase-kt/issues/86) build available: [2.5.4-wasm0](https://github.com/supabase-community/supabase-kt/releases/tag/2.5.4-wasm0)*
*Note: The `WASM-JS` target for supported modules is only available for version 2.7.0 and above*

[![](https://img.shields.io/github/release/supabase-community/supabase-kt?label=stable)](https://github.com/supabase-community/supabase-kt/releases)
[![](https://badgen.net/github/release/supabase-community/supabase-kt?label=prerelease)](https://central.sonatype.com/search?q=io.github.jan.supabase&smo=true)
[![Kotlin](https://img.shields.io/badge/kotlin-2.0.10-blue.svg?logo=kotlin)](http://kotlinlang.org)
![https://img.shields.io/badge/ktor-2.3.12-blue](https://img.shields.io/badge/ktor-2.3.12-blue)
[![Kotlin](https://img.shields.io/badge/kotlin-2.0.20-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![Ktor](https://img.shields.io/badge/ktor-3.0.0--rc--1-blue)](https://ktor.io/)
[![slack](https://img.shields.io/badge/slack-%23supabase--kt-purple.svg?logo=slack)](https://kotlinlang.slack.com/archives/C06QXPC7064)

### Links
Expand Down Expand Up @@ -96,7 +96,11 @@ val iosMain by getting {

**Note:** It is recommended to use the same Ktor version as supabase-kt:

![https://img.shields.io/badge/ktor-2.3.12-blue](https://img.shields.io/badge/ktor-2.3.12-blue)
__For 2.7.0 and above:__
[![Ktor](https://img.shields.io/badge/ktor-3.0.0--rc--1-blue)](https://ktor.io/)

__For versions below 2.7.0:__
[![Ktor](https://img.shields.io/badge/ktor-2.3.12-blue)](https://ktor.io/)

## Main Modules

Expand Down
Loading