commonMain.io.github.jan.supabase.postgrest.Utils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of postgrest-kt-jvm Show documentation
Show all versions of postgrest-kt-jvm Show documentation
Extends supabase-kt with a Postgrest Client
The newest version!
package io.github.jan.supabase.postgrest
import io.github.jan.supabase.annotations.SupabaseInternal
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.descriptors.elementNames
import kotlinx.serialization.serializerOrNull
import kotlin.reflect.KProperty1
import kotlin.reflect.typeOf
private val SNAKE_CASE_REGEX = "([a-z0-9])([A-Z])".toRegex()
@SupabaseInternal
expect fun getSerialName(property: KProperty1): String
@SupabaseInternal
internal fun String.camelToSnakeCase(): String {
return this.replace(SNAKE_CASE_REGEX, "$1_$2").lowercase()
}
@PublishedApi internal fun Map>.mapToFirstValue() = mapValues { it.value.first() }
@OptIn(ExperimentalSerializationApi::class)
@SupabaseInternal
inline fun classPropertyNames(): List = serializerOrNull(typeOf())?.descriptor?.elementNames?.toList() ?: throw IllegalArgumentException("Could not find serializer for ${T::class.simpleName}")