Skip to content

Commit d579783

Browse files
authored
Add support for WASM-JS and migrate to Ktor 3.0.0 (#311)
* Rename WASM target * Add support for wasm * Add wasmJs tests * fix build * fix detekt * Update version * update version * Update wasm code to match master changes * backport js fix to wasm-js * Add Apollo GraphQL, Compose Auth, Compose Auth Ui support * migrate to ktor 3.0.0 * bumnp apollo and version * Update version * Merge master * fix some build errors * remove image loader wasm support * add wasm js to compose auth ui * Update versions * Update version * Migrate to new Ktor Beta * Fix storage-kt * Fix another migration error * Fix sample * Fix wasmJs implementation * Fix test * Suppress compile only warning * Update docs * Fix typo * Update setup-gradle * Remove test dep * Fix invalid Ktor version badge
1 parent 3920e8a commit d579783

File tree

50 files changed

+301
-216
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+301
-216
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
java-version: '17'
2222
distribution: 'temurin'
2323
- name: Setup Gradle
24-
uses: gradle/actions/setup-gradle@v3.1.0
24+
uses: gradle/actions/setup-gradle@v4.0.1
2525
with:
2626
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
2727
cache-read-only: false

.github/workflows/detekt.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
java-version: '17'
2121
distribution: 'temurin'
2222
- name: Setup Gradle
23-
uses: gradle/actions/setup-gradle@v3.1.0
23+
uses: gradle/actions/setup-gradle@v4.0.1
2424
with:
2525
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
2626
cache-read-only: ${{ github.ref != 'refs/heads/master' }}

.github/workflows/dokka.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
java-version: '17'
3939
distribution: 'temurin'
4040
- name: Setup Gradle
41-
uses: gradle/actions/setup-gradle@v3.1.0
41+
uses: gradle/actions/setup-gradle@v4.0.1
4242
with:
4343
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
4444
cache-read-only: true

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
java-version: '17'
2828
distribution: 'temurin'
2929
- name: Setup Gradle
30-
uses: gradle/actions/setup-gradle@v3.1.0
30+
uses: gradle/actions/setup-gradle@v4.0.1
3131
with:
3232
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
3333
cache-read-only: true

.github/workflows/samples.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
java-version: '17'
2828
distribution: 'temurin'
2929
- name: Setup Gradle
30-
uses: gradle/actions/setup-gradle@v3.1.0
30+
uses: gradle/actions/setup-gradle@v4.0.1
3131
with:
3232
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
3333
cache-read-only: ${{ github.ref != 'refs/heads/master' }}

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
matrix:
1515
command: [
1616
'jvmTest testDebugUnitTest testReleaseUnitTest',
17-
'jsTest',
17+
'jsTest wasmJsTest',
1818
'iosX64Test iosSimulatorArm64Test',
1919
'macosArm64Test macosX64Test',
2020
'tvosX64Test tvosSimulatorArm64Test',
@@ -31,7 +31,7 @@ jobs:
3131
java-version: '17'
3232
distribution: 'temurin'
3333
- name: Setup Gradle
34-
uses: gradle/actions/setup-gradle@v3.1.0
34+
uses: gradle/actions/setup-gradle@v4.0.1
3535
with:
3636
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
3737
cache-read-only: ${{ github.ref != 'refs/heads/master' }}

Functions/README.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,27 @@ Extends Supabase-kt with a multiplatform Functions client.
44

55
Supported targets:
66

7-
| Target | **JVM** | **Android** | **JS** | **iOS** | **tvOS** | **watchOS** | **macOS** | **Windows** | **Linux** |
8-
|--------|---------|-------------|--------|---------|----------|-------------|-----------|-------------|-----------|
9-
| |||||| | |||
7+
| Target | **JVM** | **Android** | **JS** | **Wasm** | **Apple** | **Windows** | **Linux** |
8+
|--------|---------|-------------|--------|----------|-----------|-------------|-----------|
9+
| Status |||| | |||
1010

1111
<details>
1212

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

15-
**iOS:** iosArm64, iosSimulatorArm64, iosX64
16-
1715
**JS**: Browser, NodeJS
1816

19-
**tvOS**: tvosArm64, tvosX64, tvosSimulatorArm64
17+
**Wasm**: wasm-js
18+
19+
**Apple:**
20+
21+
- iOS: iosArm64, iosSimulatorArm64, iosX64
22+
23+
- tvOS: tvosArm64, tvosX64, tvosSimulatorArm64
2024

21-
**watchOS**: watchosArm64, watchosX64, watchosSimulatorArm64
25+
- watchOS: watchosArm64, watchosX64, watchosSimulatorArm64
2226

23-
**MacOS**: macosX64, macosArm64
27+
- MacOS: macosX64, macosArm64
2428

2529
**Windows**: mingwX64
2630

GoTrue/README.md

+14-10
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,31 @@ Extends Supabase-kt with a multiplatform GoTrue client.
44

55
Supported targets:
66

7-
| Target | **JVM** | **Android** | **JS** | **iOS** | **tvOS** | **watchOS** | **macOS** | **Windows** | **Linux** |
8-
| ------ | ------- | ----------- | ------ | ------- | -------- | ----------- | --------- | ----------- | --------- |
9-
| ||||| ☑️ | ☑️ | | ☑️ | ☑️ |
7+
| Target | **JVM** | **Android** | **JS** | **Wasm** | **Apple** | **Windows** | **Linux** |
8+
|--------|---------|-------------|--------|----------|-----------|-------------|-----------|
9+
| Status | | || | ☑️* | ☑️ | ☑️ |
1010

11-
> Native support is experimental and needs feedback
12-
>
1311
> ☑️ = No built-in OAuth support. Linux has no support for persistent session storage.
1412
13+
\* **iOS and macOS are fully supported**
14+
1515
<details>
1616

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

19-
**iOS:** iosArm64, iosSimulatorArm64, iosX64
20-
2119
**JS**: Browser, NodeJS
2220

23-
**tvOS**: tvosArm64, tvosX64, tvosSimulatorArm64
21+
**Wasm**: wasm-js
22+
23+
**Apple:**
24+
25+
- iOS: iosArm64, iosSimulatorArm64, iosX64
26+
27+
- tvOS: tvosArm64, tvosX64, tvosSimulatorArm64
2428

25-
**watchOS**: watchosArm64, watchosX64, watchosSimulatorArm64
29+
- watchOS: watchosArm64, watchosX64, watchosSimulatorArm64
2630

27-
**MacOS**: macosX64, macosArm64
31+
- MacOS: macosX64, macosArm64
2832

2933
**Windows**: mingwX64
3034

GoTrue/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ kotlin {
2929
withWatchos()
3030
withMingw()
3131
withJs()
32+
withWasmJs()
3233
}
3334
}
3435
}

GoTrue/src/desktopMain/kotlin/io/github/jan/supabase/gotrue/server/HttpCallbackRoutes.kt

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import io.github.jan.supabase.gotrue.user.UserSession
55
import io.github.jan.supabase.logging.d
66
import io.ktor.http.ContentType
77
import io.ktor.http.HttpStatusCode
8-
import io.ktor.server.application.call
98
import io.ktor.server.response.respondText
109
import io.ktor.server.routing.Routing
1110
import io.ktor.server.routing.get

GoTrue/src/desktopMain/kotlin/io/github/jan/supabase/gotrue/server/HttpCallbackServer.kt

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.jan.supabase.gotrue.server
22

3-
import io.github.jan.supabase.annotations.SupabaseExperimental
43
import io.github.jan.supabase.gotrue.Auth
54
import io.github.jan.supabase.gotrue.AuthImpl
65
import io.github.jan.supabase.gotrue.openExternalUrl
@@ -11,7 +10,6 @@ import io.ktor.http.HttpStatusCode
1110
import io.ktor.server.application.ApplicationCall
1211
import io.ktor.server.application.ApplicationStopPreparing
1312
import io.ktor.server.cio.CIO
14-
import io.ktor.server.engine.ApplicationEngineEnvironment
1513
import io.ktor.server.engine.embeddedServer
1614
import io.ktor.server.response.respondText
1715
import io.ktor.server.routing.routing
@@ -23,7 +21,6 @@ import kotlinx.coroutines.launch
2321
import kotlinx.coroutines.suspendCancellableCoroutine
2422
import kotlin.coroutines.resume
2523

26-
@OptIn(SupabaseExperimental::class)
2724
internal suspend fun createServer(
2825
url: suspend (redirect: String) -> String,
2926
auth: Auth,
@@ -41,7 +38,7 @@ internal suspend fun createServer(
4138
}
4239
coroutineScope {
4340
val timeoutScope = launch {
44-
val port = server.resolvedConnectors().first().port
41+
val port = server.engine.resolvedConnectors().first().port
4542
Auth.logger.d {
4643
"Started OAuth callback server on port $port. Opening url in browser..."
4744
}
@@ -64,7 +61,7 @@ internal suspend fun createServer(
6461
}
6562
launch {
6663
suspendCancellableCoroutine {
67-
server.environment.monitor.subscribe(ApplicationStopPreparing) { _ ->
64+
server.monitor.subscribe(ApplicationStopPreparing) { _ ->
6865
it.resume(Unit)
6966
timeoutScope.cancel()
7067
}
@@ -84,14 +81,9 @@ internal suspend fun shutdown(call: ApplicationCall, message: String) {
8481

8582
val latch = CompletableDeferred<Nothing>()
8683
call.application.launch {
84+
application.monitor.raise(ApplicationStopPreparing, environment)
8785
latch.join()
88-
89-
environment.monitor.raise(ApplicationStopPreparing, environment)
90-
if (environment is ApplicationEngineEnvironment) {
91-
environment.stop()
92-
} else {
93-
application.dispose()
94-
}
86+
application.dispose()
9587
}
9688

9789
try {
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
package io.github.jan.supabase.gotrue.providers
22

3-
import kotlinx.browser.window
4-
53
/**
64
* Configuration for external authentication providers like Google, Twitter, etc.
75
*/
8-
actual class ExternalAuthConfig: ExternalAuthConfigDefaults() {
9-
10-
/**
11-
* The URL to redirect to after a successful login.
12-
*
13-
* Defaults to `Window.location.origin`
14-
*/
15-
var redirectUrl: String = window.location.origin
16-
17-
}
6+
actual class ExternalAuthConfig: ExternalAuthConfigDefaults()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.github.jan.supabase.gotrue
2+
3+
import io.github.jan.supabase.plugins.CustomSerializationConfig
4+
5+
/**
6+
* The configuration for [Auth]
7+
*/
8+
actual class AuthConfig: CustomSerializationConfig, AuthConfigDefaults()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.github.jan.supabase.gotrue
2+
3+
import io.github.jan.supabase.annotations.SupabaseInternal
4+
import kotlinx.browser.window
5+
6+
@SupabaseInternal
7+
actual fun Auth.defaultPlatformRedirectUrl(): String? = window.location.origin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.github.jan.supabase.gotrue
2+
3+
import io.github.jan.supabase.SupabaseClient
4+
import kotlinx.browser.window
5+
6+
internal actual suspend fun SupabaseClient.openExternalUrl(url: String) {
7+
window.location.href = url
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.github.jan.supabase.gotrue.providers
2+
3+
/**
4+
* Configuration for external authentication providers like Google, Twitter, etc.
5+
*/
6+
actual class ExternalAuthConfig: ExternalAuthConfigDefaults()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.github.jan.supabase.gotrue
2+
3+
import io.github.jan.supabase.annotations.SupabaseInternal
4+
import io.ktor.util.PlatformUtils.IS_BROWSER
5+
import kotlinx.browser.window
6+
import kotlinx.coroutines.launch
7+
import org.w3c.dom.url.URL
8+
9+
@SupabaseInternal
10+
actual fun Auth.setupPlatform() {
11+
this as AuthImpl
12+
13+
fun checkForHash() {
14+
if(window.location.hash.isBlank()) return
15+
val afterHash = window.location.hash.substring(1)
16+
17+
if(!afterHash.contains('=')) {
18+
// No params after hash, no need to continue
19+
return
20+
}
21+
parseFragmentAndImportSession(afterHash) {
22+
val newURL = window.location.href.split("?")[0];
23+
window.history.replaceState(null, window.document.title, newURL);
24+
}
25+
}
26+
27+
fun checkForPCKECode() {
28+
val url = URL(window.location.href)
29+
val code = url.searchParams.get("code") ?: return
30+
authScope.launch {
31+
val session = exchangeCodeForSession(code)
32+
importSession(session)
33+
}
34+
val newURL = window.location.href.split("?")[0];
35+
window.history.replaceState(null, window.document.title, newURL);
36+
}
37+
38+
if(IS_BROWSER) {
39+
window.onhashchange = {
40+
checkForHash()
41+
}
42+
window.onload = {
43+
checkForHash()
44+
checkForPCKECode()
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import io.github.jan.supabase.gotrue.AuthConfig
2+
3+
actual fun AuthConfig.platformSettings() = Unit

Postgrest/README.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,27 @@ Extends Supabase-kt with a multiplatform Postgrest client.
44

55
Supported targets:
66

7-
| Target | **JVM** | **Android** | **JS** | **iOS** | **tvOS** | **watchOS** | **macOS** | **Windows** | **Linux** |
8-
| ------ | ------- | ----------- | ------ | ------- | -------- | ----------- | --------- | ----------- | --------- |
9-
| |||| | | ||||
7+
| Target | **JVM** | **Android** | **JS** | **Wasm** | **Apple** | **Windows** | **Linux** |
8+
|--------|---------|-------------|--------|----------|-----------|-------------|-----------|
9+
| Status | | ||| | | |
1010

1111
<details>
1212

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

15-
**iOS:** iosArm64, iosSimulatorArm64, iosX64
16-
1715
**JS**: Browser, NodeJS
1816

19-
**tvOS**: tvosArm64, tvosX64, tvosSimulatorArm64
17+
**Wasm**: wasm-js
18+
19+
**Apple:**
20+
21+
- iOS: iosArm64, iosSimulatorArm64, iosX64
22+
23+
- tvOS: tvosArm64, tvosX64, tvosSimulatorArm64
2024

21-
**watchOS**: watchosArm64, watchosX64, watchosSimulatorArm64
25+
- watchOS: watchosArm64, watchosX64, watchosSimulatorArm64
2226

23-
**MacOS**: macosX64, macosArm64
27+
- MacOS: macosX64, macosArm64
2428

2529
**Windows**: mingwX64
2630

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.github.jan.supabase.postgrest
2+
3+
import io.github.jan.supabase.annotations.SupabaseInternal
4+
import kotlin.reflect.KProperty1
5+
6+
@SupabaseInternal
7+
actual fun <T, V> getSerialName(property: KProperty1<T, V>) = property.name

README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ For information about supported Kotlin targets, see the corresponding module REA
66

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

9-
*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)*
9+
*Note: The `WASM-JS` target for supported modules is only available for version 2.7.0 and above*
1010

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

1717
### Links
@@ -96,7 +96,11 @@ val iosMain by getting {
9696

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

99-
![https://img.shields.io/badge/ktor-2.3.12-blue](https://img.shields.io/badge/ktor-2.3.12-blue)
99+
__For 2.7.0 and above:__
100+
[![Ktor](https://img.shields.io/badge/ktor-3.0.0--rc--1-blue)](https://ktor.io/)
101+
102+
__For versions below 2.7.0:__
103+
[![Ktor](https://img.shields.io/badge/ktor-2.3.12-blue)](https://ktor.io/)
100104

101105
## Main Modules
102106

0 commit comments

Comments
 (0)