Skip to content

Commit 68d38cc

Browse files
authored
Merge pull request #1 from TeamHubApp/new-api
New api
2 parents 5fa61ca + ac7c582 commit 68d38cc

File tree

43 files changed

+2225
-1394
lines changed

Some content is hidden

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

43 files changed

+2225
-1394
lines changed

build.gradle.kts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
2+
13
plugins {
2-
kotlin("multiplatform") version "1.3.50" apply false
4+
kotlin("multiplatform") version "1.3.61" apply false
35
}
46

57
buildscript {
@@ -26,18 +28,26 @@ subprojects {
2628
jcenter()
2729
}
2830

31+
tasks.withType<KotlinCompile<*>> {
32+
kotlinOptions.freeCompilerArgs += listOf(
33+
"-Xuse-experimental=kotlin.Experimental",
34+
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
35+
"-Xuse-experimental=kotlinx.serialization.ImplicitReflectionSerializer"
36+
)
37+
}
38+
2939
afterEvaluate {
3040
dependencies {
3141
"commonMainImplementation"(kotlin("stdlib-common"))
32-
"commonMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.2.2")
42+
"commonMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.3")
3343
"jsMainImplementation"(kotlin("stdlib-js"))
34-
"jsMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.2.2")
35-
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.2")
36-
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.2.2")
44+
"jsMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.3")
45+
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3")
46+
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.3.3")
3747
"jvmMainImplementation"(kotlin("stdlib-jdk8"))
38-
"jvmMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.2")
39-
"jvmMainApi"("app.teamhub:firebase-java:0.2.0")
40-
"jvmMainApi"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.2.2")
48+
"jvmMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3")
49+
"jvmMainApi"("app.teamhub:firebase-java:0.3.0")
50+
"jvmMainApi"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.3.3")
4151
}
4252
}
4353
}

firebase-app/build.gradle.kts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ repositories {
99
mavenCentral()
1010
google()
1111
}
12-
version = "0.1.0"
12+
13+
version = "0.1.0-dev"
1314

1415
android {
1516
compileSdkVersion(property("targetSdkVersion") as Int)
@@ -32,6 +33,13 @@ kotlin {
3233
}
3334
}
3435
}
36+
// js("reactnative") {
37+
// val main by compilations.getting {
38+
// kotlinOptions {
39+
// moduleKind = "commonjs"
40+
// }
41+
// }
42+
// }
3543
android {
3644
publishLibraryVariants("release", "debug")
3745
}
@@ -51,7 +59,7 @@ kotlin {
5159
}
5260
val androidMain by getting {
5361
dependencies {
54-
api("com.google.firebase:firebase-common:17.1.0")
62+
api("com.google.firebase:firebase-common:19.2.0")
5563
}
5664
}
5765
val jvmMain by getting {
@@ -73,6 +81,7 @@ tasks {
7381
into.createNewFile()
7482
into.writeText(from.readText()
7583
.replace("require('firebase-", "require('@teamhubapp/firebase-")
84+
.replace("require('kotlinx-serialization-kotlinx-serialization-runtime')", "require('@cachet/kotlinx-serialization-runtime')")
7685
)
7786
}
7887
}
@@ -90,9 +99,9 @@ tasks {
9099
dependsOn(copyPackageJson, copyJS, copySourceMap)
91100
workingDir("$buildDir/node_module")
92101
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
93-
commandLine("cmd", "/c", "npm publish --registry https://npm.pkg.github.com/")
102+
commandLine("cmd", "/c", "npm publish --registry http://localhost:4873")
94103
} else {
95-
commandLine("npm", "publish", "--registry https://npm.pkg.github.com/")
104+
commandLine("npm", "publish", "--registry http://localhost:4873")
96105
}
97106
}
98107
}

firebase-app/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@teamhubapp/firebase-app",
3-
"version": "0.1.0",
3+
"version": "0.1.0-dev9",
44
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
55
"main": "firebase-app.js",
66
"scripts": {
@@ -23,10 +23,10 @@
2323
},
2424
"homepage": "https://github.com/TeamHubApp/firebase-kotlin-multiplatform-sdk",
2525
"dependencies": {
26-
"@teamhubapp/firebase-common": "0.1.0",
26+
"@teamhubapp/firebase-common": "0.1.0-dev9",
2727
"firebase": "6.2.3",
28-
"kotlin": "1.3.50",
29-
"kotlinx-coroutines-core": "1.2.2"
28+
"kotlin": "1.3.61",
29+
"kotlinx-coroutines-core": "1.3.3"
3030
}
3131
}
3232

firebase-app/src/androidMain/kotlin/dev/teamhub/firebase/firebase.kt

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,36 @@ actual typealias FirebaseTooManyRequestsException = com.google.firebase.Firebase
1010

1111
actual typealias FirebaseApiNotAvailableException = com.google.firebase.FirebaseApiNotAvailableException
1212

13-
actual fun initializeFirebaseApp(context: Any, options: FirebaseOptions) =
14-
FirebaseApp.initializeApp(context as Context, options)
13+
actual val Firebase.app: FirebaseApp
14+
get() = FirebaseApp(com.google.firebase.FirebaseApp.getInstance())
1515

16-
actual typealias FirebaseApp = com.google.firebase.FirebaseApp
16+
actual fun Firebase.app(name: String): FirebaseApp =
17+
FirebaseApp(com.google.firebase.FirebaseApp.getInstance(name))
1718

18-
actual typealias FirebaseOptions = com.google.firebase.FirebaseOptions
19+
actual fun Firebase.initialize(context: Any?): FirebaseApp? =
20+
com.google.firebase.FirebaseApp.initializeApp(context as Context)?.let { FirebaseApp(it) }
1921

20-
actual typealias FirebaseOptionsBuilder = com.google.firebase.FirebaseOptions.Builder
22+
actual fun Firebase.initialize(context: Any?, options: FirebaseOptions, name: String): FirebaseApp =
23+
FirebaseApp(com.google.firebase.FirebaseApp.initializeApp(context as Context, options.toAndroid(), name))
2124

22-
actual fun getFirebaseApps(context: Any) = FirebaseApp.getApps(context as Context)
25+
actual fun Firebase.initialize(context: Any?, options: FirebaseOptions) =
26+
FirebaseApp(com.google.firebase.FirebaseApp.initializeApp(context as Context, options.toAndroid()))
2327

24-
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
25-
actual fun FirebaseOptionsBuilder.setApiKey(apiKey: String): FirebaseOptionsBuilder {
26-
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
28+
actual class FirebaseApp internal constructor(val android: com.google.firebase.FirebaseApp) {
29+
actual val name: String
30+
get() = android.name
31+
actual val options: FirebaseOptions
32+
get() = android.options.run { FirebaseOptions(applicationId, apiKey, databaseUrl, gaTrackingId, storageBucket, projectId) }
2733
}
2834

29-
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
30-
actual fun FirebaseOptionsBuilder.setApplicationId(applicationId: String): FirebaseOptionsBuilder {
31-
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
32-
}
33-
34-
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
35-
actual fun FirebaseOptionsBuilder.setDatabaseUrl(databaseUrl: String?): FirebaseOptionsBuilder {
36-
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
37-
}
38-
39-
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
40-
actual fun FirebaseOptionsBuilder.setStorageBucket(storageBucket: String?): FirebaseOptionsBuilder {
41-
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
42-
}
43-
44-
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
45-
actual fun FirebaseOptionsBuilder.setProjectId(projectId: String?): FirebaseOptionsBuilder {
46-
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
47-
}
48-
49-
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
50-
actual fun FirebaseOptionsBuilder.build(): FirebaseOptions {
51-
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
52-
}
53-
54-
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
55-
actual fun FirebaseOptionsBuilder.setGoogleAppId(googleAppId: String): FirebaseOptionsBuilder {
56-
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
57-
}
35+
actual fun Firebase.apps(context: Any?) = com.google.firebase.FirebaseApp.getApps(context as Context)
36+
.map { FirebaseApp(it) }
37+
38+
private fun FirebaseOptions.toAndroid() = com.google.firebase.FirebaseOptions.Builder()
39+
.setApplicationId(applicationId)
40+
.setApiKey(apiKey)
41+
.setDatabaseUrl(databaseUrl)
42+
.setGaTrackingId(gaTrackingId)
43+
.setStorageBucket(storageBucket)
44+
.setProjectId(projectId)
45+
.build()

firebase-app/src/commonMain/kotlin/dev/teamhub/firebase/firebase.kt

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,52 @@
1-
@file:Suppress("EXTENSION_SHADOWED_BY_MEMBER")
1+
@file:JvmMultifileClass
2+
@file:JvmName("CommonKt")
23
package dev.teamhub.firebase
34

4-
expect fun initializeFirebaseApp(context: Any, options: FirebaseOptions): FirebaseApp
5+
import kotlin.jvm.JvmMultifileClass
6+
import kotlin.jvm.JvmName
57

6-
expect class FirebaseApp
8+
/**
9+
* Single access point to all firebase sdks from Kotlin.
10+
*
11+
* <p>Acts as a target for extension methods provided by sdks.
12+
*/
13+
object Firebase
714

8-
expect fun getFirebaseApps(context: Any): List<FirebaseApp>
15+
expect class FirebaseApp {
16+
val name: String
17+
val options: FirebaseOptions
18+
}
919

10-
expect class FirebaseOptions
20+
/** Returns the default firebase app instance. */
21+
expect val Firebase.app: FirebaseApp
1122

12-
expect class FirebaseOptionsBuilder()
23+
/** Returns a named firebase app instance. */
24+
expect fun Firebase.app(name: String): FirebaseApp
1325

14-
expect fun FirebaseOptionsBuilder.setGoogleAppId(googleAppId: String): FirebaseOptionsBuilder
15-
expect fun FirebaseOptionsBuilder.setApiKey(apiKey: String): FirebaseOptionsBuilder
16-
expect fun FirebaseOptionsBuilder.setApplicationId(applicationId: String): FirebaseOptionsBuilder
17-
expect fun FirebaseOptionsBuilder.setDatabaseUrl(databaseUrl: String?): FirebaseOptionsBuilder
18-
expect fun FirebaseOptionsBuilder.setStorageBucket(storageBucket: String?): FirebaseOptionsBuilder
19-
expect fun FirebaseOptionsBuilder.setProjectId(projectId: String?): FirebaseOptionsBuilder
20-
expect fun FirebaseOptionsBuilder.build(): FirebaseOptions
26+
/** Returns all firebase app instances. */
27+
expect fun Firebase.apps(context: Any? = null): List<FirebaseApp>
28+
29+
/** Initializes and returns a FirebaseApp. */
30+
expect fun Firebase.initialize(context: Any? = null): FirebaseApp?
31+
32+
/** Initializes and returns a FirebaseApp. */
33+
expect fun Firebase.initialize(context: Any? = null, options: FirebaseOptions): FirebaseApp
34+
35+
/** Initializes and returns a FirebaseApp. */
36+
expect fun Firebase.initialize(context: Any? = null, options: FirebaseOptions, name: String): FirebaseApp
37+
38+
/** Returns options of default FirebaseApp */
39+
val Firebase.options: FirebaseOptions
40+
get() = Firebase.app.options
41+
42+
data class FirebaseOptions(
43+
val applicationId: String,
44+
val apiKey: String,
45+
val databaseUrl: String? = null,
46+
val gaTrackingId: String? = null,
47+
val storageBucket: String? = null,
48+
val projectId: String? = null
49+
)
2150

2251
expect open class FirebaseException : Exception
2352

firebase-app/src/jsMain/kotlin/dev/teamhub/firebase/externals.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,43 @@
11
package dev.teamhub.firebase
22

3-
import kotlin.js.Json
43
import kotlin.js.json
5-
import kotlin.reflect.KClass
6-
7-
actual typealias FirebaseApp = firebase.App
8-
9-
actual fun initializeFirebaseApp(context: Any, options: FirebaseOptions) = firebase.initializeApp(
10-
json(
11-
"apiKey" to options.apiKey,
12-
"applicationId" to options.applicationId,
13-
"databaseURL" to options.databaseUrl,
14-
"storageBucket" to options.storageBucket,
15-
"projectId" to options.projectId,
16-
"googleAppId" to options.googleAppId
17-
)
18-
)
19-
20-
actual data class FirebaseOptions constructor(
21-
val apiKey: String? = undefined,
22-
val applicationId: String? = undefined,
23-
val databaseUrl: String? = undefined,
24-
val storageBucket: String? = undefined,
25-
val projectId: String? = undefined,
26-
val googleAppId: String? = undefined
27-
)
28-
29-
actual class FirebaseOptionsBuilder actual constructor() {
30-
var options = FirebaseOptions()
31-
}
324

33-
actual open class FirebaseException(code: String?, message: String?) : Exception("$code: $message")
5+
actual val Firebase.app: FirebaseApp
6+
get() = FirebaseApp(firebase.app())
347

35-
actual fun getFirebaseApps(context: Any) = firebase.apps.toList()
8+
actual fun Firebase.app(name: String): FirebaseApp =
9+
FirebaseApp(firebase.app(name))
3610

37-
actual open class FirebaseNetworkException(code: String?, message: String?) : FirebaseException(code, message)
38-
actual open class FirebaseTooManyRequestsException(code: String?, message: String?) : FirebaseException(code, message)
39-
actual open class FirebaseApiNotAvailableException(code: String?, message: String?) : FirebaseException(code, message)
11+
actual fun Firebase.initialize(context: Any?): FirebaseApp? =
12+
throw UnsupportedOperationException("Cannot initialize firebase without options in JS")
4013

41-
actual fun FirebaseOptionsBuilder.setGoogleAppId(googleAppId: String) = options.copy(googleAppId = googleAppId).let { options = it }.let { this }
14+
actual fun Firebase.initialize(context: Any?, options: FirebaseOptions, name: String): FirebaseApp =
15+
FirebaseApp(firebase.initializeApp(options.toJson(), name))
4216

43-
actual fun FirebaseOptionsBuilder.setApiKey(apiKey: String) = options.copy(apiKey = apiKey).let { options = it }.let { this }
17+
actual fun Firebase.initialize(context: Any?, options: FirebaseOptions) =
18+
FirebaseApp(firebase.initializeApp(options.toJson()))
4419

45-
actual fun FirebaseOptionsBuilder.setApplicationId(applicationId: String) = options.copy(applicationId = applicationId).let { options = it }.let { this }
46-
47-
actual fun FirebaseOptionsBuilder.setDatabaseUrl(databaseUrl: String?) = options.copy(databaseUrl = databaseUrl).let { options = it }.let { this }
48-
49-
actual fun FirebaseOptionsBuilder.setStorageBucket(storageBucket: String?) = options.copy(storageBucket = storageBucket).let { options = it }.let { this }
20+
actual class FirebaseApp internal constructor(val js: firebase.App) {
21+
actual val name: String
22+
get() = js.name
23+
actual val options: FirebaseOptions
24+
get() = js.options.run {
25+
FirebaseOptions(applicationId, apiKey, databaseUrl, gaTrackingId, storageBucket, projectId)
26+
}
27+
}
5028

51-
actual fun FirebaseOptionsBuilder.setProjectId(projectId: String?) = options.copy(projectId = projectId).let { options = it }.let { this }
29+
actual fun Firebase.apps(context: Any?) = firebase.apps.map { FirebaseApp(it) }
5230

53-
actual fun FirebaseOptionsBuilder.build() = options
31+
private fun FirebaseOptions.toJson() = json(
32+
"apiKey" to apiKey,
33+
"applicationId" to applicationId,
34+
"databaseURL" to databaseUrl,
35+
"storageBucket" to storageBucket,
36+
"projectId" to projectId,
37+
"gaTrackingId" to gaTrackingId
38+
)
5439

40+
actual open class FirebaseException(code: String?, cause: Throwable) : Exception("$code: ${cause.message}", cause)
41+
actual open class FirebaseNetworkException(code: String?, cause: Throwable) : FirebaseException(code, cause)
42+
actual open class FirebaseTooManyRequestsException(code: String?, cause: Throwable) : FirebaseException(code, cause)
43+
actual open class FirebaseApiNotAvailableException(code: String?, cause: Throwable) : FirebaseException(code, cause)

0 commit comments

Comments
 (0)